Search in sources :

Example 76 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class ItemClimbingClaws method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
            ItemStack stack = slot.getItem();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
                ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
                if (item.wallClimbSpeed > 0) {
                    Vec3d ppos = new Vec3d(player.posX, player.posY, player.posZ);
                    Vec3d plook = player.getLookVec();
                    plook = plook.subtract(0, plook.yCoord, 0).normalize();
                    RayTraceResult r = player.world.rayTraceBlocks(ppos, ppos.add(plook.scale(.425)), false, true, false);
                    if (r != null && r.typeOfHit == RayTraceResult.Type.BLOCK) {
                        IBlockState state = player.world.getBlockState(r.getBlockPos());
                        if (state.isSideSolid(player.world, r.getBlockPos(), r.sideHit)) {
                            if (player.isSneaking()) {
                                if (player.moveForward > 0F) {
                                    player.motionY = Math.max(item.wallClimbSpeed, player.motionY);
                                } else {
                                    player.motionY = Math.max(0d, player.motionY);
                                }
                                player.fallDistance = 0;
                            } else {
                                player.motionY = Math.max(player.motionY, Math.min(player.motionY + .1d, -.15d));
                                if (player.motionY > -.666)
                                    player.fallDistance = 0;
                            }
                        }
                    }
                    break;
                }
            }
        }
        for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
            ItemStack stack = slot.getItem();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
                ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
                if (item.stepHeightBoost > 0) {
                    if (player.isSneaking())
                        player.stepHeight = .6f;
                    else
                        player.stepHeight = .6f + item.stepHeightBoost;
                    break;
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 77 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class CATileEntity method onDataPacket.

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
    readFromNBT(pkt.getNbtCompound());
    IBlockState state = getWorld().getBlockState(pos);
    getWorld().notifyBlockUpdate(pos, state, state, 3);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Example 78 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class BlockJumpPad method getTargetLocation.

@Nullable
public BlockPos getTargetLocation(BlockPos pos, World w, boolean isSneaking) {
    int range = 16;
    if (isSneaking) {
        TileEntity te = w.getTileEntity(pos);
        if (te != null && te instanceof TileEntityJumpPad) {
            BlockPos p = ((TileEntityJumpPad) te).getCustomLocation(false);
            if (p != null && w.getBlockState(p).getBlock() == this && validateLocation(p, w))
                return p;
        }
        for (int i = 3; i < range; i++) {
            BlockPos p = pos.down(i);
            IBlockState state = w.getBlockState(p);
            if (!state.isTranslucent()) {
                if (w.getBlockState(p).getBlock() == this)
                    return p;
                else
                    return null;
            }
        }
    } else {
        TileEntity te = w.getTileEntity(pos);
        if (te != null && te instanceof TileEntityJumpPad) {
            BlockPos p = ((TileEntityJumpPad) te).getCustomLocation(true);
            if (p != null && w.getBlockState(p).getBlock() == this && validateLocation(p, w))
                return p;
        }
        for (int i = 3; i < range; i++) {
            BlockPos p = pos.up(i);
            IBlockState state = w.getBlockState(p);
            if (!w.getBlockState(p).isTranslucent()) {
                if (state.getBlock() == this) {
                    if (validateLocation(p, w))
                        return p;
                    else
                        return null;
                } else
                    return null;
            }
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) Nullable(javax.annotation.Nullable)

Example 79 with IBlockState

use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.

the class BlockJumpPad method validateLocation.

public boolean validateLocation(BlockPos p, World w) {
    IBlockState state1 = w.getBlockState(p.up());
    IBlockState state2 = w.getBlockState(p.up(2));
    if (state1.getBlock().isAir(state1, w, p.up()) && state2.getBlock().isAir(state2, w, p.up(2)))
        return true;
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Example 80 with IBlockState

use of net.minecraft.block.state.IBlockState in project ImmersiveEngineering by BluSunrize.

the class TileRenderAutoWorkbench method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityAutoWorkbench te, double x, double y, double z, float partialTicks, int destroyStage) {
    if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false))
        return;
    //Grab model + correct eextended state
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = te.getPos();
    IBlockState state = getWorld().getBlockState(blockPos);
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    state = state.getBlock().getActualState(state, getWorld(), blockPos);
    state = state.withProperty(IEProperties.DYNAMICRENDER, true);
    IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
    //Initialize Tesselator and VertexBuffer
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer worldRenderer = tessellator.getBuffer();
    //Outer GL Wrapping, initial translation
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    if (te.mirrored)
        GlStateManager.scale(te.facing.getFrontOffsetX() == 0 ? -1 : 1, 1, te.facing.getFrontOffsetZ() == 0 ? -1 : 1);
    //Item Displacement
    float[][] itemDisplays = new float[te.processQueue.size()][];
    //Animations
    float drill = 0;
    float lift = 0;
    float press = 0;
    float liftPress = 0;
    for (int i = 0; i < itemDisplays.length; i++) {
        MultiblockProcess<IMultiblockRecipe> process = te.processQueue.get(i);
        if (process == null || process.processTick <= 0 || process.processTick == process.maxTicks)
            continue;
        //+partialTicks
        float processTimer = ((float) process.processTick) / process.maxTicks * 180;
        if (processTimer <= 9)
            continue;
        float itemX = -1;
        float itemY = -.34375f;
        float itemZ = -.9375f;
        float itemAngle = 90f;
        if (//slide
        processTimer <= 24) {
            itemAngle = 67.5f;
            if (processTimer <= 19) {
                itemZ += .25 + (19 - processTimer) / 10f * .5f;
                itemY += .25 + (19 - processTimer) / 10f * .21875f;
            } else {
                itemZ += (24 - processTimer) / 5f * .25f;
                itemY += (24 - processTimer) / 5f * .25f;
            }
        } else if (processTimer <= 40) {
            itemX += (processTimer - 24) / 16f;
        } else if (processTimer <= 100) {
            itemX += 1;
            float drillStep = 0;
            if (processTimer <= 60) {
                lift = (processTimer - 40) / 20f * .3125f;
                drillStep = 4 + (60 - processTimer) * 4;
            } else if (processTimer <= 80) {
                lift = .3125f;
                drillStep = 4;
            } else {
                lift = (100 - processTimer) / 20f * .3125f;
                drillStep = 4 + (processTimer - 80) * 4;
            }
            if (drillStep > 0)
                drill = processTimer % drillStep / drillStep * 360;
            itemY += Math.max(0, lift - .0625);
        } else if (processTimer <= 116) {
            itemX += 1;
            itemZ += (processTimer - 100) / 16f;
        } else if (processTimer <= 132) {
            itemX += 1 + (processTimer - 116) / 16f;
            itemZ += 1;
        } else if (processTimer <= 172) {
            itemX += 2;
            itemZ += 1;
            if (processTimer <= 142)
                press = (processTimer - 132) / 10f;
            else if (processTimer <= 162)
                press = 1;
            else
                press = (172 - processTimer) / 10f;
            liftPress = press * .0625f;
            itemY += liftPress;
        } else if (processTimer <= 180) {
            itemX += 2 + (processTimer - 172) / 16f;
            itemZ += 1;
        }
        itemDisplays[i] = new float[] { processTimer, itemX, itemY, itemZ, itemAngle };
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    ItemStack blueprintStack = te.inventory[0];
    if (blueprintStack != null)
        renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "blueprint");
    GlStateManager.translate(0, lift, 0);
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "lift");
    GlStateManager.translate(0, -lift, 0);
    EnumFacing f = te.getFacing();
    float tx = f == EnumFacing.WEST ? -.9375f : f == EnumFacing.EAST ? .9375f : 0;
    float tz = f == EnumFacing.NORTH ? -.9375f : f == EnumFacing.SOUTH ? .9375f : 0;
    GlStateManager.translate(tx, 0, tz);
    GlStateManager.rotate(drill, 0, 1, 0);
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "drill");
    GlStateManager.rotate(-drill, 0, 1, 0);
    GlStateManager.translate(-tx, 0, -tz);
    tx = f == EnumFacing.WEST ? -.59375f : f == EnumFacing.EAST ? .59375f : 0;
    tz = f == EnumFacing.NORTH ? -.59375f : f == EnumFacing.SOUTH ? .59375f : 0;
    GlStateManager.translate(tx, -.21875, tz);
    GlStateManager.rotate(press * 90, -f.getFrontOffsetZ(), 0, f.getFrontOffsetX());
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "press");
    GlStateManager.rotate(-press * 90, -f.getFrontOffsetZ(), 0, f.getFrontOffsetX());
    GlStateManager.translate(-tx, .21875, -tz);
    GlStateManager.translate(0, liftPress, 0);
    renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "pressLift");
    GlStateManager.translate(0, -liftPress, 0);
    RenderHelper.enableStandardItemLighting();
    GlStateManager.popMatrix();
    switch(f) {
        case NORTH:
            break;
        case SOUTH:
            GlStateManager.rotate(180, 0, 1, 0);
            break;
        case WEST:
            GlStateManager.rotate(90, 0, 1, 0);
            break;
        case EAST:
            GlStateManager.rotate(-90, 0, 1, 0);
            break;
    }
    //DRAW ITEMS HERE
    for (int i = 0; i < itemDisplays.length; i++) if (itemDisplays[i] != null) {
        MultiblockProcess<IMultiblockRecipe> process = te.processQueue.get(i);
        if (process == null || !(process instanceof MultiblockProcessInWorld))
            continue;
        float scale = .3125f;
        List<ItemStack> dList = ((MultiblockProcessInWorld) process).getDisplayItem();
        if (!dList.isEmpty())
            if (dList.size() < 2) {
                GlStateManager.translate(itemDisplays[i][1], itemDisplays[i][2], itemDisplays[i][3]);
                GlStateManager.rotate(itemDisplays[i][4], 1, 0, 0);
                GlStateManager.scale(scale, scale, .5f);
                ClientUtils.mc().getRenderItem().renderItem(dList.get(0), ItemCameraTransforms.TransformType.FIXED);
                GlStateManager.scale(1 / scale, 1 / scale, 2);
                GlStateManager.rotate(-itemDisplays[i][4], 1, 0, 0);
                GlStateManager.translate(-itemDisplays[i][1], -itemDisplays[i][2], -itemDisplays[i][3]);
            } else {
                int size = dList.size();
                int lines = (int) Math.ceil(size / 2f);
                float spacer = (lines - 1) * .234375f;
                for (int d = 0; d < size; d++) {
                    float oX = (size > 2 ? -.3125f : 0) + (lines - d / 2) * .0625f + d % 2 * .3125f;
                    float oZ = -spacer / 2f + d / 2 * .234375f;
                    float oY = 0;
                    float localItemX = itemDisplays[i][1] + oX;
                    float localItemY = itemDisplays[i][2] + oY;
                    float localItemZ = itemDisplays[i][3] + oZ;
                    float subProcess = itemDisplays[i][0] - d / 2 * 4;
                    float localAngle = itemDisplays[i][4];
                    if (//slide
                    subProcess <= 24) {
                        localAngle = 67.5f;
                        if (subProcess <= 19) {
                            localItemZ = -1 + .25f + (19 - subProcess) / 10f * .5f;
                            localItemY = -.34375f + .25f + (19 - subProcess) / 10f * .21875f;
                        } else {
                            localItemZ = -1 + (oZ - (24 - subProcess) / 5f * oZ);
                            localItemY = -.34375f + (24 - subProcess) / 5f * .25f;
                        }
                    }
                    GlStateManager.translate(localItemX, localItemY, localItemZ);
                    GlStateManager.rotate(localAngle, 1, 0, 0);
                    GlStateManager.scale(scale, scale, .5f);
                    ClientUtils.mc().getRenderItem().renderItem(dList.get(d), ItemCameraTransforms.TransformType.FIXED);
                    GlStateManager.scale(1 / scale, 1 / scale, 2);
                    GlStateManager.rotate(-localAngle, 1, 0, 0);
                    GlStateManager.translate(-localItemX, -localItemY, -localItemZ);
                }
            }
    }
    //Blueprint
    double playerDistanceSq = ClientUtils.mc().thePlayer.getDistanceSq(blockPos);
    if (blueprintStack != null && playerDistanceSq < 1000) {
        BlueprintCraftingRecipe[] recipes = BlueprintCraftingRecipe.findRecipes(ItemNBTHelper.getString(blueprintStack, "blueprint"));
        BlueprintCraftingRecipe recipe = (te.selectedRecipe < 0 || te.selectedRecipe >= recipes.length) ? null : recipes[te.selectedRecipe];
        BlueprintLines blueprint = recipe == null ? null : getBlueprintDrawable(recipe, te.getWorld());
        if (blueprint != null) {
            //Width depends on distance
            float lineWidth = playerDistanceSq < 6 ? 3 : playerDistanceSq < 25 ? 2 : playerDistanceSq < 40 ? 1 : .5f;
            GlStateManager.translate(-.195, .125, .97);
            GlStateManager.rotate(-45, 1, 0, 0);
            GlStateManager.disableCull();
            GlStateManager.disableTexture2D();
            GlStateManager.enableBlend();
            float scale = .0375f / (blueprint.textureScale / 16f);
            GlStateManager.scale(scale, -scale, scale);
            GlStateManager.color(1, 1, 1, 1);
            blueprint.draw(lineWidth);
            GlStateManager.scale(1 / scale, -1 / scale, 1 / scale);
            GlStateManager.enableAlpha();
            GlStateManager.enableTexture2D();
            GlStateManager.enableCull();
        }
    }
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MultiblockProcess(blusunrize.immersiveengineering.common.blocks.metal.TileEntityMultiblockMetal.MultiblockProcess) EnumFacing(net.minecraft.util.EnumFacing) MultiblockProcessInWorld(blusunrize.immersiveengineering.common.blocks.metal.TileEntityMultiblockMetal.MultiblockProcessInWorld) BlueprintCraftingRecipe(blusunrize.immersiveengineering.api.crafting.BlueprintCraftingRecipe) IMultiblockRecipe(blusunrize.immersiveengineering.api.crafting.IMultiblockRecipe) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)2979 BlockPos (net.minecraft.util.math.BlockPos)1194 Block (net.minecraft.block.Block)797 ItemStack (net.minecraft.item.ItemStack)517 EnumFacing (net.minecraft.util.EnumFacing)420 TileEntity (net.minecraft.tileentity.TileEntity)339 World (net.minecraft.world.World)255 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)171 EntityPlayer (net.minecraft.entity.player.EntityPlayer)136 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)126 ArrayList (java.util.ArrayList)125 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)121 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)95 Entity (net.minecraft.entity.Entity)94 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)93 ItemBlock (net.minecraft.item.ItemBlock)89 BlockPos (net.minecraft.util.BlockPos)84 Random (java.util.Random)82 Vec3d (net.minecraft.util.math.Vec3d)81 RayTraceResult (net.minecraft.util.math.RayTraceResult)76