Search in sources :

Example 1 with PlayerControllerMP

use of net.minecraft.client.multiplayer.PlayerControllerMP in project GregTech by GregTechCE.

the class ToolRenderHandler method onRenderWorldLast.

@SubscribeEvent
public void onRenderWorldLast(RenderWorldLastEvent event) {
    Minecraft mc = Minecraft.getMinecraft();
    // render block damage progress for all breakers
    for (int breakerEntityId : event.getContext().damagedBlocks.keySet()) {
        Entity breakerEntity = mc.world.getEntityByID(breakerEntityId);
        if (!(breakerEntity instanceof EntityPlayer)) {
            continue;
        }
        EntityPlayer entityPlayer = (EntityPlayer) breakerEntity;
        ItemStack itemStack = entityPlayer.getHeldItem(EnumHand.MAIN_HAND);
        if (!(itemStack.getItem() instanceof IAOEItem)) {
            continue;
        }
        DestroyBlockProgress progress = event.getContext().damagedBlocks.get(breakerEntityId);
        RayTraceResult rayTraceResult = RayTracer.retraceBlock(mc.world, entityPlayer, progress.getPosition());
        if (rayTraceResult == null || rayTraceResult.typeOfHit != Type.BLOCK) {
            continue;
        }
        List<BlockPos> aoeBlocksToRender = ((IAOEItem) itemStack.getItem()).getAOEBlocks(itemStack, entityPlayer, rayTraceResult);
        int breakProgress = progress.getPartialBlockDamage();
        preRenderDamagedBlocks();
        drawBlockDamageTexture(mc, Tessellator.getInstance(), mc.getRenderViewEntity(), event.getPartialTicks(), aoeBlocksToRender, breakProgress);
        postRenderDamagedBlocks();
    }
    // render block selection only for current player
    PlayerControllerMP playerController = mc.playerController;
    if (!playerController.getIsHittingBlock()) {
        ItemStack itemStack = mc.player.getHeldItem(EnumHand.MAIN_HAND);
        if (itemStack.getItem() instanceof IAOEItem) {
            RayTraceResult rayTraceResult = RayTracer.retrace(mc.player);
            if (rayTraceResult != null && rayTraceResult.typeOfHit == Type.BLOCK) {
                List<BlockPos> aoeBlocksToRender = ((IAOEItem) itemStack.getItem()).getAOEBlocks(itemStack, mc.player, rayTraceResult);
                preRenderSelectionOutline();
                drawSelectionOutlines(mc, aoeBlocksToRender, mc.getRenderViewEntity(), event.getPartialTicks());
                postRenderSelectionOutline();
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) PlayerControllerMP(net.minecraft.client.multiplayer.PlayerControllerMP) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IAOEItem(gregtech.api.items.toolitem.IAOEItem) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IAOEItem (gregtech.api.items.toolitem.IAOEItem)1 Minecraft (net.minecraft.client.Minecraft)1 PlayerControllerMP (net.minecraft.client.multiplayer.PlayerControllerMP)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1