Search in sources :

Example 11 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method doRayTrace.

public RaytraceResult doRayTrace(World world, int x, int y, int z, EntityPlayer player) {
    double reachDistance = 5;
    if (player instanceof EntityPlayerMP) {
        reachDistance = ((EntityPlayerMP) player).theItemInWorldManager.getBlockReachDistance();
    }
    double eyeHeight = world.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight();
    Vec3 lookVec = player.getLookVec();
    Vec3 origin = Vec3.createVectorHelper(player.posX, player.posY + eyeHeight, player.posZ);
    Vec3 direction = origin.addVector(lookVec.xCoord * reachDistance, lookVec.yCoord * reachDistance, lookVec.zCoord * reachDistance);
    return doRayTrace(world, x, y, z, origin, direction);
}
Also used : Vec3(net.minecraft.util.Vec3) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 12 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project LogisticsPipes by RS485.

the class DummyContainer method detectAndSendChanges.

@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
    for (int i = 0; i < inventorySlots.size(); ++i) {
        if (inventorySlots.get(i) instanceof IFuzzySlot) {
            IFuzzySlot fuzzySlot = (IFuzzySlot) inventorySlots.get(i);
            BitSet set = inventoryFuzzySlotsContent.get(i);
            if (set == null) {
                set = fuzzySlot.getFuzzyFlags().getBitSet();
                MainProxy.sendToPlayerList(PacketHandler.getPacket(FuzzySlotSettingsPacket.class).setSlotNumber(fuzzySlot.getSlotId()).setFlags(set), crafters);
                inventoryFuzzySlotsContent.set(i, set);
            } else {
                BitSet setB = fuzzySlot.getFuzzyFlags().getBitSet();
                if (!set.equals(setB)) {
                    MainProxy.sendToPlayerList(PacketHandler.getPacket(FuzzySlotSettingsPacket.class).setSlotNumber(fuzzySlot.getSlotId()).setFlags(setB), crafters);
                    inventoryFuzzySlotsContent.set(i, setB);
                }
            }
        }
        ItemStack itemstack = ((Slot) inventorySlots.get(i)).getStack();
        ItemStack itemstack1 = (ItemStack) inventoryItemStacks.get(i);
        if (!ItemStack.areItemStacksEqual(itemstack1, itemstack)) {
            itemstack1 = itemstack == null ? null : itemstack.copy();
            inventoryItemStacks.set(i, itemstack1);
            for (Object crafter : crafters) {
                boolean revert = false;
                if (overrideMCAntiSend && crafter instanceof EntityPlayerMP && ((EntityPlayerMP) crafter).isChangingQuantityOnly) {
                    ((EntityPlayerMP) crafter).isChangingQuantityOnly = false;
                    revert = true;
                }
                ((ICrafting) crafter).sendSlotContents(this, i, itemstack1);
                if (revert) {
                    ((EntityPlayerMP) crafter).isChangingQuantityOnly = true;
                }
            }
        }
    }
    overrideMCAntiSend = false;
}
Also used : IFuzzySlot(logisticspipes.interfaces.IFuzzySlot) BitSet(java.util.BitSet) Slot(net.minecraft.inventory.Slot) IFuzzySlot(logisticspipes.interfaces.IFuzzySlot) ICrafting(net.minecraft.inventory.ICrafting) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) FuzzySlotSettingsPacket(logisticspipes.network.packets.gui.FuzzySlotSettingsPacket)

Example 13 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project BetterStorage by copygirl.

the class ChristmasEventHandler method onPlayerDeath.

@SubscribeEvent
public void onPlayerDeath(LivingDeathEvent event) {
    if (!(event.entity instanceof EntityPlayerMP))
        return;
    EntityPlayer player = (EntityPlayer) event.entity;
    BetterChristmasProperties properties = EntityUtils.getProperties(player, BetterChristmasProperties.class);
    NBTTagCompound entityData = player.getEntityData();
    NBTTagCompound persistent = entityData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
    entityData.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistent);
    NBTTagCompound propertiesCompound = new NBTTagCompound();
    properties.saveNBTData(propertiesCompound);
    persistent.setTag(BetterChristmasProperties.identifier, propertiesCompound);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 14 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project BetterStorage by copygirl.

the class ItemBackpack method onPlaceBackpack.

/** Places an equipped backpack when the player right clicks
	 *  on the ground while sneaking and holding nothing. */
public static boolean onPlaceBackpack(EntityPlayer player, int x, int y, int z, int side) {
    if (player.getCurrentEquippedItem() != null || !player.isSneaking())
        return false;
    ItemStack backpack = ItemBackpack.getBackpack(player);
    if (backpack == null)
        return false;
    boolean success = false;
    if (!ItemBackpack.isBackpackOpen(player)) {
        // Try to place the backpack as if it was being held and used by the player.
        success = backpack.getItem().onItemUse(backpack, player, player.worldObj, x, y, z, side, 0, 0, 0);
        if (backpack.stackSize <= 0) {
            ItemBackpack.setBackpack(player, null, null);
            backpack = null;
        }
    }
    // Make sure the client has the same information as the server. It does not sync when backpackChestplate is disabled because there are no changes to the slot in that case.
    if (!player.worldObj.isRemote && success && player instanceof EntityPlayerMP && BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
        ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S2FPacketSetSlot(0, 6, backpack));
    }
    if (success)
        player.swingItem();
    return success;
}
Also used : S2FPacketSetSlot(net.minecraft.network.play.server.S2FPacketSetSlot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 15 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project BetterStorage by copygirl.

the class BackpackHandler method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(EntityInteractEvent event) {
    if (event.entity.worldObj.isRemote || !(event.entity instanceof EntityPlayerMP) || !(event.target instanceof EntityLivingBase) || (((EntityPlayerMP) event.entity).playerNetServerHandler == null) || ((event.target instanceof EntityPlayer) && !BetterStorage.globalConfig.getBoolean(GlobalConfig.enableBackpackInteraction)))
        return;
    EntityPlayerMP player = (EntityPlayerMP) event.entity;
    EntityLivingBase target = (EntityLivingBase) event.target;
    if (ItemBackpack.openBackpack(player, target))
        player.swingItem();
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)163 EntityPlayer (net.minecraft.entity.player.EntityPlayer)32 ItemStack (net.minecraft.item.ItemStack)23 TileEntity (net.minecraft.tileentity.TileEntity)18 Entity (net.minecraft.entity.Entity)17 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)15 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)14 BlockPos (net.minecraft.util.math.BlockPos)14 Block (net.minecraft.block.Block)11 IBlockState (net.minecraft.block.state.IBlockState)8 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 World (net.minecraft.world.World)8 WrongUsageException (net.minecraft.command.WrongUsageException)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)7 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)5 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)5 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)5