Added ability to install inset lights in top-aligned catwalks (PR#215, sergii)
This commit is contained in:
parent
df903f5f79
commit
a38eaa6f99
5 changed files with 280 additions and 22 deletions
|
@ -387,12 +387,16 @@ public class ModContent
|
|||
Registries.addBlock("iron_inset_light", ()->new StandardBlocks.DirectedWaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_FACING_PLACEMENT|StandardBlocks.CFG_OPPOSITE_PLACEMENT|StandardBlocks.CFG_AI_PASSABLE,
|
||||
BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.5f, 8f).sound(SoundType.METAL).lightLevel((state)->15).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(5.2,5.2,0, 10.8,10.8,0.3)
|
||||
new AABB[] {
|
||||
Auxiliaries.getPixeledAABB( 5,7,0, 11, 9,0.375),
|
||||
Auxiliaries.getPixeledAABB( 6,6,0, 10,10,0.375),
|
||||
Auxiliaries.getPixeledAABB( 7,5,0, 9,11,0.375)
|
||||
}
|
||||
));
|
||||
Registries.addBlock("iron_floor_edge_light", ()->new StandardBlocks.DirectedWaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_LOOK_PLACEMENT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_AI_PASSABLE,
|
||||
BlockBehaviour.Properties.of(Material.METAL, MaterialColor.METAL).strength(0.5f, 8f).sound(SoundType.METAL).lightLevel((state)->15).noOcclusion(),
|
||||
Auxiliaries.getPixeledAABB(5,0,0, 11,2,0.5)
|
||||
Auxiliaries.getPixeledAABB(5,0,0, 11,1.8125,0.375)
|
||||
));
|
||||
Registries.addBlock("iron_ceiling_edge_light", ()->new StandardBlocks.DirectedWaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT|StandardBlocks.CFG_LOOK_PLACEMENT|StandardBlocks.CFG_HORIZIONTAL|StandardBlocks.CFG_AI_PASSABLE,
|
||||
|
@ -537,8 +541,12 @@ public class ModContent
|
|||
Auxiliaries.getPixeledAABB(15, 0, 0, 16, 16, 1),
|
||||
Auxiliaries.getPixeledAABB(15, 0,15, 16, 16,16),
|
||||
Auxiliaries.getPixeledAABB( 0, 0,15, 1, 16,16)
|
||||
),
|
||||
Auxiliaries.getUnionShape( // base with inset light
|
||||
Auxiliaries.getPixeledAABB( 0,14,0, 16,16,16)
|
||||
)
|
||||
}
|
||||
},
|
||||
Registries.getBlock("iron_inset_light")
|
||||
));
|
||||
Registries.addBlock("steel_catwalk_stairs", ()->new EdCatwalkStairsBlock(
|
||||
StandardBlocks.CFG_CUTOUT,
|
||||
|
|
|
@ -62,7 +62,7 @@ public class EdCatwalkBlock extends StandardBlocks.HorizontalFourWayWaterLoggabl
|
|||
|
||||
public static boolean place_consume(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, int shrink)
|
||||
{
|
||||
if(!world.setBlock(pos, state, 1|2)) return false;
|
||||
if(!world.setBlock(pos, state, Block.UPDATE_ALL)) return false;
|
||||
world.playSound(player, pos, SoundEvents.METAL_PLACE, SoundSource.BLOCKS, 1f, 1f);
|
||||
if((!player.isCreative()) && (!world.isClientSide())) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
|
@ -94,7 +94,7 @@ public class EdCatwalkBlock extends StandardBlocks.HorizontalFourWayWaterLoggabl
|
|||
place_state = place_state.setValue(WATERLOGGED,adjacent_state.getFluidState().getType()==Fluids.WATER);
|
||||
place_consume(place_state, world, adjacent_pos, player, hand, 1);
|
||||
}
|
||||
return world.isClientSide() ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
}
|
||||
if(block == railing_block) {
|
||||
Direction face = hit.getDirection();
|
||||
|
@ -108,14 +108,14 @@ public class EdCatwalkBlock extends StandardBlocks.HorizontalFourWayWaterLoggabl
|
|||
} else {
|
||||
// far automatic placement
|
||||
face = Direction.getNearest(player.getLookAngle().x, 0, player.getLookAngle().z);
|
||||
List<Direction> free_sides = Arrays.stream(Direction.values()).filter(d->d.getAxis().isHorizontal() && (world.getBlockState(pos.relative(d)).getBlock()!=this)).collect(Collectors.toList());
|
||||
if(free_sides.isEmpty()) return world.isClientSide() ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
|
||||
List<Direction> free_sides = Arrays.stream(Direction.values()).filter(d -> d.getAxis().isHorizontal() && (world.getBlockState(pos.relative(d)).getBlock() != this)).toList();
|
||||
if(free_sides.isEmpty()) return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
if(!free_sides.contains(face)) face = free_sides.get(0);
|
||||
}
|
||||
BooleanProperty railing = getDirectionProperty(face);
|
||||
boolean add = (!state.getValue(railing));
|
||||
place_consume(state.setValue(railing, add), world, pos, player, hand, add ? 1 : -1);
|
||||
return world.isClientSide() ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
}
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class EdCatwalkBlock extends StandardBlocks.HorizontalFourWayWaterLoggabl
|
|||
List<ItemStack> drops = new ArrayList<>();
|
||||
drops.add(new ItemStack(state.getBlock().asItem()));
|
||||
int n = (state.getValue(NORTH)?1:0)+(state.getValue(EAST)?1:0)+(state.getValue(SOUTH)?1:0)+(state.getValue(WEST)?1:0);
|
||||
if(n > 0) drops.add(new ItemStack(ModContent.getBlock("steel_railing"), n));
|
||||
if(n > 0) drops.add(new ItemStack(railing_block, n));
|
||||
return drops;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,13 +13,16 @@ import net.minecraft.core.Direction;
|
|||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.item.context.DirectionalPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
|
@ -33,20 +36,24 @@ import wile.engineersdecor.ModContent;
|
|||
import wile.engineersdecor.libmc.blocks.StandardBlocks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class EdCatwalkTopAlignedBlock extends StandardBlocks.WaterLoggable
|
||||
{
|
||||
public static final IntegerProperty VARIANT = IntegerProperty.create("variant", 0, 3);
|
||||
public static final IntegerProperty VARIANT = IntegerProperty.create("variant", 0, 4);
|
||||
protected final List<VoxelShape> variant_shapes;
|
||||
protected final Block inset_light_block;
|
||||
|
||||
public EdCatwalkTopAlignedBlock(long config, BlockBehaviour.Properties properties, final VoxelShape[] variant_shapes)
|
||||
public EdCatwalkTopAlignedBlock(long config, BlockBehaviour.Properties properties, final VoxelShape[] variant_shapes, final Block inset_light_block)
|
||||
{
|
||||
super(config, properties, variant_shapes[0]);
|
||||
registerDefaultState(super.defaultBlockState().setValue(VARIANT, 0));
|
||||
this.variant_shapes = VARIANT.getPossibleValues().stream().map(i->(i<variant_shapes.length) ? (variant_shapes[i]) : (Shapes.block())).collect(Collectors.toList());
|
||||
this.inset_light_block = inset_light_block;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,16 +88,27 @@ public class EdCatwalkTopAlignedBlock extends StandardBlocks.WaterLoggable
|
|||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit)
|
||||
{
|
||||
final Item item = player.getItemInHand(hand).getItem();
|
||||
if(item != this.asItem()) return InteractionResult.PASS;
|
||||
if(hit.getDirection().getAxis().isHorizontal()) return InteractionResult.PASS;
|
||||
BlockPos adjacent_pos = pos.relative(player.getDirection());
|
||||
BlockState adjacent_state = world.getBlockState(adjacent_pos);
|
||||
if(adjacent_state.canBeReplaced(new DirectionalPlaceContext(world, adjacent_pos, hit.getDirection().getOpposite(), player.getItemInHand(hand), hit.getDirection()))) {
|
||||
BlockState place_state = defaultBlockState();
|
||||
place_state = place_state.setValue(WATERLOGGED,adjacent_state.getFluidState().getType()==Fluids.WATER);
|
||||
EdCatwalkBlock.place_consume(adapted_state(place_state, world, adjacent_pos), world, adjacent_pos, player, hand, 1);
|
||||
if((!(item instanceof BlockItem))) return InteractionResult.PASS;
|
||||
final Block block = ((BlockItem)item).getBlock();
|
||||
if(block == this) {
|
||||
if (hit.getDirection().getAxis().isHorizontal()) return InteractionResult.PASS;
|
||||
BlockPos adjacent_pos = pos.relative(player.getDirection());
|
||||
BlockState adjacent_state = world.getBlockState(adjacent_pos);
|
||||
if (adjacent_state.canBeReplaced(new DirectionalPlaceContext(world, adjacent_pos, hit.getDirection().getOpposite(), player.getItemInHand(hand), hit.getDirection()))) {
|
||||
BlockState place_state = defaultBlockState();
|
||||
place_state = place_state.setValue(WATERLOGGED, adjacent_state.getFluidState().getType() == Fluids.WATER);
|
||||
EdCatwalkBlock.place_consume(adapted_state(place_state, world, adjacent_pos), world, adjacent_pos, player, hand, 1);
|
||||
}
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
}
|
||||
return world.isClientSide() ? InteractionResult.SUCCESS : InteractionResult.CONSUME;
|
||||
if(block == inset_light_block && hit.getDirection() == Direction.DOWN) {
|
||||
int currentVariant = state.getValue(VARIANT);
|
||||
if (!(currentVariant == 0 || currentVariant == 4)) return InteractionResult.PASS;
|
||||
boolean add = currentVariant == 0;
|
||||
EdCatwalkBlock.place_consume(adapted_state(state.setValue(VARIANT, add ? 4 : 0), world, pos), world, pos, player, hand, add ? 1 : -1);
|
||||
return InteractionResult.sidedSuccess(world.isClientSide());
|
||||
}
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,10 +120,31 @@ public class EdCatwalkTopAlignedBlock extends StandardBlocks.WaterLoggable
|
|||
private BlockState adapted_state(BlockState state, LevelAccessor world, BlockPos pos)
|
||||
{
|
||||
BlockState below = world.getBlockState(pos.below());
|
||||
if((below == null) || (state == null)) return state;
|
||||
if (state == null || state.getValue(VARIANT) == 4) return state;
|
||||
if((below.getBlock() == ModContent.getBlock("thick_steel_pole")) || (below.getBlock() == ModContent.getBlock("thick_steel_pole_head"))) return state.setValue(VARIANT, 1);
|
||||
if((below.getBlock() == ModContent.getBlock("thin_steel_pole")) || (below.getBlock() == ModContent.getBlock("thin_steel_pole_head"))) return state.setValue(VARIANT, 2);
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) {
|
||||
return state.getValue(VARIANT) == 4
|
||||
? inset_light_block.getLightEmission(inset_light_block.defaultBlockState().setValue(StandardBlocks.Directed.FACING, Direction.UP), level, pos)
|
||||
: super.getLightEmission(state, level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDynamicDropList()
|
||||
{ return true; }
|
||||
|
||||
@Override
|
||||
public List<ItemStack> dropList(BlockState state, Level world, @Nullable BlockEntity te, boolean explosion)
|
||||
{
|
||||
if(world.isClientSide()) return Collections.singletonList(ItemStack.EMPTY);
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
drops.add(new ItemStack(state.getBlock().asItem()));
|
||||
if (state.getValue(VARIANT) == 4) drops.add(new ItemStack(inset_light_block, 1));
|
||||
return drops;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue