use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinMinecraftServer method onServerTickEnd.
@Inject(method = "tick", at = @At(value = "RETURN"))
public void onServerTickEnd(CallbackInfo ci) {
int lastAnimTick = SpongeCommonEventFactory.lastAnimationPacketTick;
int lastPrimaryTick = SpongeCommonEventFactory.lastPrimaryPacketTick;
int lastSecondaryTick = SpongeCommonEventFactory.lastSecondaryPacketTick;
if (SpongeCommonEventFactory.lastAnimationPlayer != null) {
EntityPlayerMP player = SpongeCommonEventFactory.lastAnimationPlayer.get();
if (player != null && lastAnimTick != lastPrimaryTick && lastAnimTick != lastSecondaryTick && lastAnimTick != 0 && lastAnimTick - lastPrimaryTick > 3 && lastAnimTick - lastSecondaryTick > 3) {
BlockSnapshot blockSnapshot = BlockSnapshot.NONE;
EnumFacing side = null;
final RayTraceResult result = SpongeImplHooks.rayTraceEyes(player, SpongeImplHooks.getBlockReachDistance(player) + 1);
// Hit non-air block
if (result != null && result.getBlockPos() != null) {
blockSnapshot = new Location<>((World) player.world, VecHelper.toVector3d(result.getBlockPos())).createSnapshot();
side = result.sideHit;
}
Sponge.getCauseStackManager().pushCause(player);
if (!player.getHeldItemMainhand().isEmpty()) {
if (SpongeCommonEventFactory.callInteractItemEventPrimary(player, player.getHeldItemMainhand(), EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec), blockSnapshot).isCancelled()) {
SpongeCommonEventFactory.lastAnimationPacketTick = 0;
Sponge.getCauseStackManager().popCause();
return;
}
}
if (side != null) {
SpongeCommonEventFactory.callInteractBlockEventPrimary(player, blockSnapshot, EnumHand.MAIN_HAND, side, VecHelper.toVector3d(result.hitVec));
} else {
SpongeCommonEventFactory.callInteractBlockEventPrimary(player, EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec));
}
Sponge.getCauseStackManager().popCause();
}
}
SpongeCommonEventFactory.lastAnimationPacketTick = 0;
TimingsManager.FULL_SERVER_TICK.stopTiming();
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class InventoryUtil method getDoubleChestInventory.
public static Optional<Inventory> getDoubleChestInventory(TileEntityChest chest) {
// BlockChest#getContainer(World, BlockPos, boolean) without isBlocked() check
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) {
BlockPos blockpos = chest.getPos().offset(enumfacing);
TileEntity tileentity1 = chest.getWorld().getTileEntity(blockpos);
if (tileentity1 instanceof TileEntityChest && tileentity1.getBlockType() == chest.getBlockType()) {
InventoryLargeChest inventory;
if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
inventory = new InventoryLargeChest("container.chestDouble", chest, (TileEntityChest) tileentity1);
} else {
inventory = new InventoryLargeChest("container.chestDouble", (TileEntityChest) tileentity1, chest);
}
return Optional.of((Inventory) inventory);
}
}
return Optional.empty();
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinBlockBannerHanging method getStateWithData.
@Override
public Optional<BlockState> getStateWithData(IBlockState blockState, ImmutableDataManipulator<?, ?> manipulator) {
if (manipulator instanceof ImmutableDirectionalData) {
final Direction direction = ((ImmutableDirectionalData) manipulator).direction().get();
final EnumFacing facing = DirectionResolver.getFor(direction);
return Optional.of((BlockState) blockState.withProperty(BlockBanner.FACING, facing));
}
return super.getStateWithData(blockState, manipulator);
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinBlockBannerHanging method getDirectionalData.
private ImmutableDirectionalData getDirectionalData(IBlockState blockState) {
final EnumFacing facing = blockState.getValue(BlockBanner.FACING);
final Direction direction = DirectionResolver.getFor(facing);
return ImmutableDataCachingUtil.getManipulator(ImmutableSpongeDirectionalData.class, direction);
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinBlockBannerHanging method getStateWithValue.
@Override
public <E> Optional<BlockState> getStateWithValue(IBlockState blockState, Key<? extends BaseValue<E>> key, E value) {
if (key.equals(Keys.DIRECTION)) {
final Direction direction = (Direction) value;
final EnumFacing facing = DirectionResolver.getFor(direction);
return Optional.of((BlockState) blockState.withProperty(BlockBanner.FACING, facing));
}
return super.getStateWithValue(blockState, key, value);
}
Aggregations