use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.
the class CartAssemblerBlockItem method tryPlaceAssembler.
public boolean tryPlaceAssembler(UseOnContext context) {
BlockPos pos = context.getClickedPos();
Level world = context.getLevel();
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
Player player = context.getPlayer();
if (player == null)
return false;
if (!(block instanceof BaseRailBlock)) {
Lang.sendStatus(player, "block.cart_assembler.invalid");
return false;
}
RailShape shape = ((BaseRailBlock) block).getRailDirection(state, world, pos, null);
if (shape != RailShape.EAST_WEST && shape != RailShape.NORTH_SOUTH)
return false;
BlockState newState = AllBlocks.CART_ASSEMBLER.getDefaultState().setValue(CartAssemblerBlock.RAIL_SHAPE, shape);
CartAssembleRailType newType = null;
for (CartAssembleRailType type : CartAssembleRailType.values()) if (type.matches(state))
newType = type;
if (newType == null)
return false;
if (world.isClientSide)
return true;
newState = newState.setValue(CartAssemblerBlock.RAIL_TYPE, newType);
if (state.hasProperty(ControllerRailBlock.BACKWARDS))
newState = newState.setValue(CartAssemblerBlock.BACKWARDS, state.getValue(ControllerRailBlock.BACKWARDS));
else {
Direction direction = player.getMotionDirection();
newState = newState.setValue(CartAssemblerBlock.BACKWARDS, direction.getAxisDirection() == AxisDirection.POSITIVE);
}
world.setBlockAndUpdate(pos, newState);
if (!player.isCreative())
context.getItemInHand().shrink(1);
return true;
}
use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.
the class MinecartContraptionItem method useOn.
// Taken and adjusted from MinecartItem
@Override
public InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
BlockPos blockpos = context.getClickedPos();
BlockState blockstate = world.getBlockState(blockpos);
if (!blockstate.is(BlockTags.RAILS)) {
return InteractionResult.FAIL;
} else {
ItemStack itemstack = context.getItemInHand();
if (!world.isClientSide) {
RailShape railshape = blockstate.getBlock() instanceof BaseRailBlock ? ((BaseRailBlock) blockstate.getBlock()).getRailDirection(blockstate, world, blockpos, null) : RailShape.NORTH_SOUTH;
double d0 = 0.0D;
if (railshape.isAscending()) {
d0 = 0.5D;
}
AbstractMinecart abstractminecartentity = AbstractMinecart.createMinecart(world, (double) blockpos.getX() + 0.5D, (double) blockpos.getY() + 0.0625D + d0, (double) blockpos.getZ() + 0.5D, this.minecartType);
if (itemstack.hasCustomHoverName())
abstractminecartentity.setCustomName(itemstack.getHoverName());
Player player = context.getPlayer();
world.addFreshEntity(abstractminecartentity);
addContraptionToMinecart(world, itemstack, abstractminecartentity, player == null ? null : player.getDirection());
}
itemstack.shrink(1);
return InteractionResult.SUCCESS;
}
}
use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.
the class BlockStateGen method cartAssembler.
public static NonNullBiConsumer<DataGenContext<Block, CartAssemblerBlock>, RegistrateBlockstateProvider> cartAssembler() {
return (c, p) -> p.getVariantBuilder(c.get()).forAllStates(state -> {
CartAssembleRailType type = state.getValue(CartAssemblerBlock.RAIL_TYPE);
Boolean powered = state.getValue(CartAssemblerBlock.POWERED);
Boolean backwards = state.getValue(CartAssemblerBlock.BACKWARDS);
RailShape shape = state.getValue(CartAssemblerBlock.RAIL_SHAPE);
int yRotation = shape == RailShape.EAST_WEST ? 270 : 0;
if (backwards)
yRotation += 180;
return ConfiguredModel.builder().modelFile(p.models().getExistingFile(p.modLoc("block/" + c.getName() + "/block_" + type.getSerializedName() + (powered ? "_powered" : "")))).rotationY(yRotation % 360).build();
});
}
use of net.minecraft.world.level.block.state.properties.RailShape in project Botania by VazkiiMods.
the class BehaviourPoolMinecart method execute.
@Nonnull
@Override
public ItemStack execute(BlockSource source, ItemStack stack) {
Direction enumfacing = source.getBlockState().getValue(DispenserBlock.FACING);
Level world = source.getLevel();
double d0 = source.x() + (double) enumfacing.getStepX() * 1.125D;
double d1 = Math.floor(source.y()) + (double) enumfacing.getStepY();
double d2 = source.z() + (double) enumfacing.getStepZ() * 1.125D;
BlockPos blockpos = source.getPos().relative(enumfacing);
BlockState iblockstate = world.getBlockState(blockpos);
RailShape railshape = iblockstate.getBlock() instanceof BaseRailBlock ? iblockstate.getValue(((BaseRailBlock) iblockstate.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
double d3;
if (iblockstate.is(BlockTags.RAILS)) {
if (railshape.isAscending()) {
d3 = 0.6D;
} else {
d3 = 0.1D;
}
} else {
if (!iblockstate.isAir() || !world.getBlockState(blockpos.below()).is(BlockTags.RAILS)) {
return this.behaviourDefaultDispenseItem.dispense(source, stack);
}
BlockState iblockstate1 = world.getBlockState(blockpos.below());
RailShape railshape1 = iblockstate1.getBlock() instanceof BaseRailBlock ? iblockstate1.getValue(((BaseRailBlock) iblockstate1.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
if (enumfacing != Direction.DOWN && railshape1.isAscending()) {
d3 = -0.4D;
} else {
d3 = -0.9D;
}
}
AbstractMinecart entityminecart = new EntityPoolMinecart(world, d0, d1 + d3, d2);
if (stack.hasCustomHoverName()) {
entityminecart.setCustomName(stack.getHoverName());
}
world.addFreshEntity(entityminecart);
stack.shrink(1);
return stack;
}
use of net.minecraft.world.level.block.state.properties.RailShape in project Botania by VazkiiMods.
the class ItemPoolMinecart method useOn.
// [VanillaCopy] MinecartItem
@Nonnull
@Override
public InteractionResult useOn(UseOnContext context) {
Level world = context.getLevel();
BlockPos blockPos = context.getClickedPos();
BlockState blockState = world.getBlockState(blockPos);
if (!blockState.is(BlockTags.RAILS)) {
return InteractionResult.FAIL;
} else {
ItemStack itemStack = context.getItemInHand();
if (!world.isClientSide) {
RailShape railShape = blockState.getBlock() instanceof BaseRailBlock ? blockState.getValue(((BaseRailBlock) blockState.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
double d = 0.0D;
if (railShape.isAscending()) {
d = 0.5D;
}
AbstractMinecart abstractMinecartEntity = new EntityPoolMinecart(world, (double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.0625D + d, (double) blockPos.getZ() + 0.5D);
if (itemStack.hasCustomHoverName()) {
abstractMinecartEntity.setCustomName(itemStack.getHoverName());
}
world.addFreshEntity(abstractMinecartEntity);
}
itemStack.shrink(1);
return InteractionResult.sidedSuccess(world.isClientSide);
}
}
Aggregations