Search in sources :

Example 16 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project TecTech by Technus.

the class ConstructableTriggerItem method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ) {
    TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
    if (tTileEntity == null || aPlayer instanceof FakePlayer) {
        return aPlayer instanceof EntityPlayerMP;
    }
    if (aPlayer instanceof EntityPlayerMP) {
        // struct gen
        if (aPlayer.isSneaking() && aPlayer.capabilities.isCreativeMode) {
            if (tTileEntity instanceof IGregTechTileEntity) {
                IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity();
                if (metaTE instanceof IConstructable) {
                    ((IConstructable) metaTE).construct(aStack.stackSize, false);
                } else if (multiblockMap.containsKey(metaTE.getClass().getCanonicalName())) {
                    multiblockMap.get(metaTE.getClass().getCanonicalName()).construct(aStack.stackSize, false, tTileEntity, ((IGregTechTileEntity) tTileEntity).getFrontFacing());
                }
            } else if (tTileEntity instanceof IConstructable) {
                ((IConstructable) tTileEntity).construct(aStack.stackSize, false);
            } else if (multiblockMap.containsKey(tTileEntity.getClass().getCanonicalName())) {
                multiblockMap.get(tTileEntity.getClass().getCanonicalName()).construct(aStack.stackSize, false, tTileEntity, aSide);
            }
        }
        return true;
    } else if (aPlayer instanceof EntityClientPlayerMP) {
        // if ((!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode)) {
        if (tTileEntity instanceof IGregTechTileEntity) {
            IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity();
            if (metaTE instanceof IConstructable) {
                ((IConstructable) metaTE).construct(aStack.stackSize, true);
                TecTech.proxy.printInchat(((IConstructable) metaTE).getStructureDescription(aStack.stackSize));
                return false;
            } else if (multiblockMap.containsKey(metaTE.getClass().getCanonicalName())) {
                multiblockMap.get(metaTE.getClass().getCanonicalName()).construct(aStack.stackSize, true, tTileEntity, ((IGregTechTileEntity) tTileEntity).getFrontFacing());
                TecTech.proxy.printInchat(multiblockMap.get(metaTE.getClass().getCanonicalName()).getDescription(aStack.stackSize));
                return false;
            }
        } else if (tTileEntity instanceof IConstructable) {
            ((IConstructable) tTileEntity).construct(aStack.stackSize, true);
            TecTech.proxy.printInchat(((IConstructable) tTileEntity).getStructureDescription(aStack.stackSize));
            return false;
        } else if (multiblockMap.containsKey(tTileEntity.getClass().getCanonicalName())) {
            multiblockMap.get(tTileEntity.getClass().getCanonicalName()).construct(aStack.stackSize, true, tTileEntity, aSide);
            TecTech.proxy.printInchat(multiblockMap.get(tTileEntity.getClass().getCanonicalName()).getDescription(aStack.stackSize));
            return false;
        }
    // } else {
    // if(tTileEntity instanceof IGregTechTileEntity) {
    // IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity();
    // if (metaTE instanceof IConstructable) {
    // TecTech.proxy.printInchat(((IConstructable) metaTE).getStructureDescription(aStack.stackSize));
    // return false;
    // } else if(multiblockMap.containsKey(metaTE.getClass().getCanonicalName())){
    // TecTech.proxy.printInchat(multiblockMap.get(metaTE.getClass().getCanonicalName()).getDescription(aStack.stackSize));
    // return false;
    // }
    // } else if(tTileEntity instanceof IConstructable){
    // TecTech.proxy.printInchat(((IConstructable) tTileEntity).getStructureDescription(aStack.stackSize));
    // return false;
    // } else if(multiblockMap.containsKey(tTileEntity.getClass().getCanonicalName())){
    // TecTech.proxy.printInchat(multiblockMap.get(tTileEntity.getClass().getCanonicalName()).getDescription(aStack.stackSize));
    // return false;
    // }
    // }
    }
    return false;
}
Also used : IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) EntityClientPlayerMP(net.minecraft.client.entity.EntityClientPlayerMP) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IConstructable(com.github.technus.tectech.thing.metaTileEntity.IConstructable) FakePlayer(net.minecraftforge.common.util.FakePlayer) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity)

Example 17 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project TecTech by Technus.

the class EuMeterGT method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ) {
    TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
    if (tTileEntity == null || aPlayer instanceof FakePlayer) {
        return aPlayer instanceof EntityPlayerMP;
    }
    if (aPlayer instanceof EntityPlayerMP && !aPlayer.isSneaking() && tTileEntity instanceof IGregTechTileEntity) {
        if (tTileEntity instanceof BaseMetaTileEntity) {
            GT_Utility.sendChatToPlayer(aPlayer, EnumChatFormatting.AQUA + "----- X:" + aX + " Y:" + aY + " Z:" + aZ + " D:" + aWorld.provider.dimensionId + " S:" + aSide + " -----");
            GT_Utility.sendChatToPlayer(aPlayer, "Stored energy: " + EnumChatFormatting.YELLOW + (((BaseMetaTileEntity) tTileEntity).getUniversalEnergyStored()) + EnumChatFormatting.RESET + '/' + EnumChatFormatting.GREEN + (((BaseMetaTileEntity) tTileEntity).getUniversalEnergyCapacity()));
            GT_Utility.sendChatToPlayer(aPlayer, "Stored EU: " + EnumChatFormatting.YELLOW + (((BaseMetaTileEntity) tTileEntity).getStoredEU()) + EnumChatFormatting.RESET + '/' + EnumChatFormatting.GREEN + (((BaseMetaTileEntity) tTileEntity).getEUCapacity()));
            GT_Utility.sendChatToPlayer(aPlayer, "Average I/O: " + EnumChatFormatting.YELLOW + (((BaseMetaTileEntity) tTileEntity).getAverageElectricInput()) + EnumChatFormatting.RESET + '/' + EnumChatFormatting.YELLOW + (((BaseMetaTileEntity) tTileEntity).getAverageElectricOutput()));
            GT_Utility.sendChatToPlayer(aPlayer, "Voltage I/O (max): " + EnumChatFormatting.GOLD + (((BaseMetaTileEntity) tTileEntity).getInputVoltage()) + EnumChatFormatting.RESET + '/' + EnumChatFormatting.GOLD + (((BaseMetaTileEntity) tTileEntity).getOutputVoltage()));
            GT_Utility.sendChatToPlayer(aPlayer, "Voltage I/O max: " + EnumChatFormatting.RED + (((BaseMetaTileEntity) tTileEntity).getMaxSafeInput()) + EnumChatFormatting.RESET + '/' + EnumChatFormatting.RED + (((BaseMetaTileEntity) tTileEntity).getMaxEnergyOutput()));
            GT_Utility.sendChatToPlayer(aPlayer, "Amperage I/O (max): " + EnumChatFormatting.GOLD + (((BaseMetaTileEntity) tTileEntity).getInputAmperage()) + EnumChatFormatting.RESET + '/' + EnumChatFormatting.GOLD + (((BaseMetaTileEntity) tTileEntity).getOutputAmperage()));
            GT_Utility.sendChatToPlayer(aPlayer, "Side capabilities: " + (((BaseMetaTileEntity) tTileEntity).inputEnergyFrom((byte) aSide) ? "input " : "") + (((BaseMetaTileEntity) tTileEntity).outputsEnergyTo((byte) aSide) ? "output " : ""));
            return true;
        } else if (tTileEntity instanceof BaseMetaPipeEntity) {
            if (((BaseMetaPipeEntity) tTileEntity).getMetaTileEntity() instanceof GT_MetaPipeEntity_Cable) {
                ArrayList<String> tList = new ArrayList<>();
                GT_Utility.getCoordinateScan(tList, aPlayer, aWorld, 1, aX, aY, aZ, aSide, hitX, hitY, hitZ);
                for (String str : tList) {
                    GT_Utility.sendChatToPlayer(aPlayer, str);
                }
            }
            return true;
        }
    }
    if (!(aPlayer instanceof EntityPlayerMP)) {
        GT_Utility.doSoundAtClient(Reference.MODID + ":fx_scan", 1, 1.0F, (double) aX, (double) aY, (double) aZ);
    }
    return false;
}
Also used : IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) BaseMetaTileEntity(gregtech.api.metatileentity.BaseMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) GT_MetaPipeEntity_Cable(gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Cable) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) BaseMetaTileEntity(gregtech.api.metatileentity.BaseMetaTileEntity) BaseMetaPipeEntity(gregtech.api.metatileentity.BaseMetaPipeEntity) ArrayList(java.util.ArrayList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 18 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project TecTech by Technus.

the class FrontRotationTriggerItem method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float hitX, float hitY, float hitZ) {
    TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
    if (tTileEntity == null || aPlayer instanceof FakePlayer) {
        return aPlayer instanceof EntityPlayerMP;
    }
    if (aPlayer instanceof EntityPlayerMP) {
        if (tTileEntity instanceof IGregTechTileEntity) {
            IMetaTileEntity metaTE = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity();
            if (metaTE instanceof IFrontRotation) {
                ((IFrontRotation) metaTE).rotateAroundFrontPlane(!aPlayer.isSneaking());
                System.out.println("DID SHIT");
                return true;
            }
        } else if (tTileEntity instanceof IFrontRotation) {
            ((IFrontRotation) tTileEntity).rotateAroundFrontPlane(!aPlayer.isSneaking());
            return true;
        }
    }
    return false;
}
Also used : IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IGregTechTileEntity(gregtech.api.interfaces.tileentity.IGregTechTileEntity) IFrontRotation(com.github.technus.tectech.thing.metaTileEntity.IFrontRotation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) FakePlayer(net.minecraftforge.common.util.FakePlayer) IMetaTileEntity(gregtech.api.interfaces.metatileentity.IMetaTileEntity)

Example 19 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project Wizardry by TeamWizardry.

the class BlockUtils method breakBlock.

/**
 * Tries breaking a block safely and fires an event for it.
 *
 * @return Whether the block was successfully broken
 */
public static boolean breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nullable IBlockState oldState, @Nullable EntityPlayerMP player, boolean drop) {
    if (!world.isBlockLoaded(pos))
        return false;
    EntityPlayerMP playerMP;
    if (player == null) {
        playerMP = new FakePlayer((WorldServer) world, breaker);
        playerMP.setPosition(pos.getX(), pos.getY(), pos.getZ());
    } else
        playerMP = player;
    if (player != null && !(player instanceof FakePlayer))
        if (!hasBreakPermission(world, pos, playerMP))
            return false;
    if (oldState == null)
        oldState = world.getBlockState(pos);
    BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, oldState, playerMP);
    MinecraftForge.EVENT_BUS.post(event);
    return !event.isCanceled() && (drop ? world.destroyBlock(pos, true) : world.setBlockToAir(pos));
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) BlockEvent(net.minecraftforge.event.world.BlockEvent) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 20 with FakePlayer

use of net.minecraftforge.common.util.FakePlayer in project BuildCraft by BuildCraft.

the class TileQuarry method forceChunkLoading.

public void forceChunkLoading(Ticket ticket) {
    if (chunkTicket == null) {
        chunkTicket = ticket;
    }
    Set<ChunkPos> chunks = Sets.newHashSet();
    ChunkPos quarryChunk = new ChunkPos(pos.getX() >> 4, pos.getZ() >> 4);
    chunks.add(quarryChunk);
    ForgeChunkManager.forceChunk(ticket, quarryChunk);
    if (box.isInitialized()) {
        for (int chunkX = box.min().getX() >> 4; chunkX <= box.max().getX() >> 4; chunkX++) {
            for (int chunkZ = box.min().getZ() >> 4; chunkZ <= box.max().getZ() >> 4; chunkZ++) {
                ChunkPos chunk = new ChunkPos(chunkX, chunkZ);
                ForgeChunkManager.forceChunk(ticket, chunk);
                chunks.add(chunk);
            }
        }
    }
    if (placedBy != null && !(placedBy instanceof FakePlayer)) {
        placedBy.addChatMessage(new TextComponentTranslation("chat.buildcraft.quarry.chunkloadInfo", getPos().getX(), getPos().getY(), getPos().getZ(), chunks.size()));
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Blueprint(buildcraft.core.blueprints.Blueprint) BptBuilderBlueprint(buildcraft.core.blueprints.BptBuilderBlueprint) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Aggregations

FakePlayer (net.minecraftforge.common.util.FakePlayer)73 ItemStack (net.minecraft.item.ItemStack)26 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 IBlockState (net.minecraft.block.state.IBlockState)14 BlockPos (net.minecraft.util.math.BlockPos)11 EntityItem (net.minecraft.entity.item.EntityItem)10 World (net.minecraft.world.World)8 TileEntity (net.minecraft.tileentity.TileEntity)7 Block (net.minecraft.block.Block)6 BaseBlock (mcjty.lib.container.BaseBlock)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 IGregTechTileEntity (gregtech.api.interfaces.tileentity.IGregTechTileEntity)3 MannequinFakePlayer (riskyken.armourersWorkshop.client.render.MannequinFakePlayer)3 PlayerPointer (riskyken.armourersWorkshop.common.data.PlayerPointer)3 SacrificeKnifeUsedEvent (WayofTime.alchemicalWizardry.api.event.SacrificeKnifeUsedEvent)2 IMinerStats (cavern.api.IMinerStats)2