Search in sources :

Example 91 with EnumFacing

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();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Location(org.spongepowered.api.world.Location) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 92 with EnumFacing

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();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Example 93 with EnumFacing

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);
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Direction(org.spongepowered.api.util.Direction) ImmutableDirectionalData(org.spongepowered.api.data.manipulator.immutable.block.ImmutableDirectionalData)

Example 94 with EnumFacing

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);
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Direction(org.spongepowered.api.util.Direction)

Example 95 with EnumFacing

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);
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Direction(org.spongepowered.api.util.Direction)

Aggregations

EnumFacing (net.minecraft.util.EnumFacing)1673 BlockPos (net.minecraft.util.math.BlockPos)491 IBlockState (net.minecraft.block.state.IBlockState)403 TileEntity (net.minecraft.tileentity.TileEntity)392 ItemStack (net.minecraft.item.ItemStack)192 Block (net.minecraft.block.Block)158 ArrayList (java.util.ArrayList)121 World (net.minecraft.world.World)114 Vec3d (net.minecraft.util.math.Vec3d)104 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)98 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)88 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)73 EntityPlayer (net.minecraft.entity.player.EntityPlayer)65 FluidStack (net.minecraftforge.fluids.FluidStack)65 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)63 Nullable (javax.annotation.Nullable)51 List (java.util.List)48 Nonnull (javax.annotation.Nonnull)47 HashSet (java.util.HashSet)43 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)43