use of vazkii.botania.common.entity.EntityPoolMinecart 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 vazkii.botania.common.entity.EntityPoolMinecart 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