Search in sources :

Example 61 with EnumFacing

use of net.minecraft.util.EnumFacing in project Bookshelf by Darkhax-Minecraft.

the class BlockBasicChest method getContainer.

@Override
public ILockableContainer getContainer(World world, BlockPos pos, boolean locked) {
    final TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof TileEntityBasicChest)) {
        return null;
    } else {
        ILockableContainer myChest = (TileEntityBasicChest) tile;
        final IChestType myType = ((TileEntityBasicChest) tile).getType();
        if (!locked && this.isBlocked(world, pos)) {
            return null;
        } else {
            for (final EnumFacing facing : EnumFacing.Plane.HORIZONTAL) {
                final BlockPos adjPos = pos.offset(facing);
                final TileEntity adjTile = world.getTileEntity(adjPos);
                if (world.getBlockState(adjPos).getBlock() == this && adjTile instanceof TileEntityBasicChest && ((TileEntityBasicChest) adjTile).getType() == myType) {
                    if (this.isBlocked(world, adjPos)) {
                        return null;
                    }
                    if (facing != EnumFacing.WEST && facing != EnumFacing.NORTH) {
                        myChest = new InventoryLargeChest("container.chestDouble", myChest, (TileEntityBasicChest) adjTile);
                    } else {
                        myChest = new InventoryLargeChest("container.chestDouble", (TileEntityBasicChest) adjTile, myChest);
                    }
                }
            }
            return myChest;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) TileEntityBasicChest(net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest) BlockPos(net.minecraft.util.math.BlockPos)

Example 62 with EnumFacing

use of net.minecraft.util.EnumFacing in project Bookshelf by Darkhax-Minecraft.

the class BlockBasicChest method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    final EnumFacing facing = EnumFacing.getHorizontal(MathHelper.floor(placer.rotationYaw * 4.0F / 360.0F + 0.5D) & 3).getOpposite();
    state = state.withProperty(FACING, facing);
    final BlockPos northPos = pos.north();
    final BlockPos southPos = pos.south();
    final BlockPos westPos = pos.west();
    final BlockPos eastPos = pos.east();
    final IChestType myType = this.getCustomType(stack);
    final boolean northChest = myType == this.getCustomType(worldIn, northPos);
    final boolean southChest = myType == this.getCustomType(worldIn, southPos);
    final boolean westChest = myType == this.getCustomType(worldIn, westPos);
    final boolean eastChest = myType == this.getCustomType(worldIn, eastPos);
    if (!northChest && !southChest && !westChest && !eastChest) {
        worldIn.setBlockState(pos, state, 3);
    } else if (facing.getAxis() != EnumFacing.Axis.X || !northChest && !southChest) {
        if (facing.getAxis() == EnumFacing.Axis.Z && (westChest || eastChest)) {
            if (westChest) {
                this.setState(worldIn, westPos, state, 3);
            } else {
                this.setState(worldIn, eastPos, state, 3);
            }
            worldIn.setBlockState(pos, state, 3);
        } else {
            final EnumFacing corrected = facing.rotateY();
            this.setState(worldIn, pos, state.withProperty(FACING, corrected), 3);
            if (northChest) {
                this.setState(worldIn, northPos, state.withProperty(FACING, corrected), 3);
            } else if (southChest) {
                this.setState(worldIn, southPos, state.withProperty(FACING, corrected), 3);
            } else if (westChest) {
                this.setState(worldIn, westPos, state.withProperty(FACING, corrected), 3);
            } else if (eastChest) {
                this.setState(worldIn, eastPos, state.withProperty(FACING, corrected), 3);
            }
        }
    } else {
        if (northChest) {
            this.setState(worldIn, northPos, state, 3);
        } else {
            this.setState(worldIn, southPos, state, 3);
        }
        worldIn.setBlockState(pos, state, 3);
    }
    final TileEntity te = worldIn.getTileEntity(pos);
    if (te instanceof TileEntityBasicChest) {
        final TileEntityBasicChest chest = (TileEntityBasicChest) te;
        if (stack.hasDisplayName()) {
            chest.setCustomName(stack.getDisplayName());
        }
        chest.setType(myType);
    }
    this.onBlockAdded(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IChestType(net.darkhax.bookshelf.builder.ChestBuilder.IChestType) EnumFacing(net.minecraft.util.EnumFacing) TileEntityBasicChest(net.darkhax.bookshelf.block.tileentity.TileEntityBasicChest) BlockPos(net.minecraft.util.math.BlockPos)

Example 63 with EnumFacing

use of net.minecraft.util.EnumFacing in project ImmersiveEngineering by BluSunrize.

the class TileRenderBucketWheel method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBucketWheel tile, double x, double y, double z, float f, int destroyStage) {
    if (!tile.formed || !tile.getWorld().isBlockLoaded(tile.getPos(), false) || tile.isDummy())
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    if (model == null) {
        state = state.withProperty(IEProperties.DYNAMICRENDER, true);
        model = blockRenderer.getModelForState(state);
    }
    OBJState objState = null;
    HashMap<String, String> texMap = new HashMap<>();
    if (state instanceof IExtendedBlockState) {
        ArrayList<String> list = Lists.newArrayList("bucketWheel");
        synchronized (tile.digStacks) {
            for (int i = 0; i < tile.digStacks.length; i++) if (tile.digStacks[i] != null) {
                list.add("dig" + i);
                Block b = Block.getBlockFromItem(tile.digStacks[i].getItem());
                IBlockState digState = b != null ? b.getStateFromMeta(tile.digStacks[i].getMetadata()) : Blocks.STONE.getDefaultState();
                IBakedModel digModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(digState);
                if (digModel != null && digModel.getParticleTexture() != null)
                    texMap.put("dig" + i, digModel.getParticleTexture().getIconName());
            }
        }
        objState = new OBJState(list, true);
    }
    Tessellator tessellator = Tessellator.getInstance();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    EnumFacing facing = tile.facing;
    if (tile.mirrored) {
        GlStateManager.scale(facing.getAxis() == Axis.X ? -1 : 1, 1, facing.getAxis() == Axis.Z ? -1 : 1);
        GlStateManager.disableCull();
    }
    float dir = tile.facing == EnumFacing.SOUTH ? 90 : tile.facing == EnumFacing.NORTH ? -90 : tile.facing == EnumFacing.EAST ? 180 : 0;
    GlStateManager.rotate(dir, 0, 1, 0);
    float rot = tile.rotation + (float) (tile.active ? IEConfig.Machines.excavator_speed * f : 0);
    GlStateManager.rotate(rot, 1, 0, 0);
    RenderHelper.disableStandardItemLighting();
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer worldRenderer = tessellator.getBuffer();
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5, -.5, -.5);
    List<BakedQuad> quads;
    if (model instanceof IESmartObjModel)
        quads = ((IESmartObjModel) model).getQuads(state, null, 0, objState, texMap, true);
    else
        quads = model.getQuads(state, null, 0);
    ClientUtils.renderModelTESR(quads, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    worldRenderer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.enableCull();
    if (tile.mirrored) {
        GlStateManager.enableCull();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IESmartObjModel(blusunrize.immersiveengineering.client.models.IESmartObjModel) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 64 with EnumFacing

use of net.minecraft.util.EnumFacing in project AgriCraft by AgriCraft.

the class BlockWaterPad method getExtendedState.

@Override
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) {
    AgriSideMetaMatrix connection = new AgriSideMetaMatrix();
    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        final IBlockState stateAt = world.getBlockState(pos.offset(facing));
        final byte value = (byte) (stateAt.getBlock() == state.getBlock() ? 1 : 0);
        connection.set(facing, value);
    }
    return connection.writeToBlockState(state);
}
Also used : AgriSideMetaMatrix(com.infinityraider.agricraft.api.v1.util.AgriSideMetaMatrix) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing)

Example 65 with EnumFacing

use of net.minecraft.util.EnumFacing in project AgriCraft by AgriCraft.

the class DebugModeCheckSoil method debugActionBlockClicked.

@Override
public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    FuzzyStack soil = FuzzyStack.from(world.getBlockState(pos)).orElse(null);
    String type = AgriApi.getSoilRegistry().all().stream().filter(s -> s.isVarient(soil)).map(s -> s.getName()).findFirst().orElse("Unknown Soil");
    MessageUtil.messagePlayer(player, "{0} Soil Info:", FMLCommonHandler.instance().getSide());
    MessageUtil.messagePlayer(player, " - Soil Type: \"{0}\"", type);
}
Also used : ItemStack(net.minecraft.item.ItemStack) DebugMode(com.infinityraider.infinitylib.utility.debug.DebugMode) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) EnumHand(net.minecraft.util.EnumHand) EnumFacing(net.minecraft.util.EnumFacing) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) BlockPos(net.minecraft.util.math.BlockPos) FuzzyStack(com.infinityraider.agricraft.api.v1.util.FuzzyStack) MessageUtil(com.infinityraider.infinitylib.utility.MessageUtil) FuzzyStack(com.infinityraider.agricraft.api.v1.util.FuzzyStack)

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