Search in sources :

Example 81 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project PneumaticCraft by MineMaarten.

the class SemiBlockManager method onServerTick.

@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
    for (ISemiBlock semiBlock : addingBlocks) {
        Chunk chunk = semiBlock.getWorld().getChunkFromBlockCoords(semiBlock.getPos().chunkPosX, semiBlock.getPos().chunkPosZ);
        getOrCreateMap(chunk).put(semiBlock.getPos(), semiBlock);
        chunk.setChunkModified();
        for (EntityPlayerMP player : syncList.get(chunk)) {
            NetworkHandler.sendTo(new PacketSetSemiBlock(semiBlock), player);
            PacketDescription descPacket = semiBlock.getDescriptionPacket();
            if (descPacket != null)
                NetworkHandler.sendTo(descPacket, player);
        }
    }
    addingBlocks.clear();
    for (Chunk removingChunk : chunksMarkedForRemoval) {
        if (!removingChunk.isChunkLoaded) {
            semiBlocks.remove(removingChunk);
            syncList.remove(removingChunk);
        }
    }
    chunksMarkedForRemoval.clear();
    for (Map<ChunkPosition, ISemiBlock> map : semiBlocks.values()) {
        for (ISemiBlock semiBlock : map.values()) {
            if (!semiBlock.isInvalid())
                semiBlock.update();
        }
        Iterator<ISemiBlock> iterator = map.values().iterator();
        while (iterator.hasNext()) {
            if (iterator.next().isInvalid()) {
                iterator.remove();
            }
        }
    }
}
Also used : PacketDescription(pneumaticCraft.common.network.PacketDescription) ChunkPosition(net.minecraft.world.ChunkPosition) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Chunk(net.minecraft.world.chunk.Chunk) PacketSetSemiBlock(pneumaticCraft.common.network.PacketSetSemiBlock) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 82 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project PneumaticCraft by MineMaarten.

the class SemiBlockManager method setSemiBlock.

private void setSemiBlock(World world, int x, int y, int z, ISemiBlock semiBlock, Chunk chunk) {
    if (semiBlock != null && !registeredTypes.containsValue(semiBlock.getClass()))
        throw new IllegalStateException("ISemiBlock \"" + semiBlock + "\" was not registered!");
    ChunkPosition pos = new ChunkPosition(x, y, z);
    if (semiBlock != null) {
        semiBlock.initialize(world, pos);
        addingBlocks.add(semiBlock);
    } else {
        ISemiBlock removedBlock = getOrCreateMap(chunk).get(pos);
        if (removedBlock != null) {
            removedBlock.invalidate();
            for (EntityPlayerMP player : syncList.get(chunk)) {
                NetworkHandler.sendTo(new PacketSetSemiBlock(pos, null), player);
            }
        }
    }
    chunk.setChunkModified();
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketSetSemiBlock(pneumaticCraft.common.network.PacketSetSemiBlock)

Example 83 with EntityPlayerMP

use of net.minecraft.entity.player.EntityPlayerMP in project PneumaticCraft by MineMaarten.

the class TileEntityAirCannon method fire.

private synchronized boolean fire() {
    Entity itemShot = getCloseEntityIfUpgraded();
    if (getPressure(ForgeDirection.UNKNOWN) >= PneumaticValues.MIN_PRESSURE_AIR_CANNON && (itemShot != null || inventory[0] != null)) {
        double[] velocity = getVelocityVector(heightAngle, rotationAngle, getForce());
        addAir((int) (-500 * getForce()), ForgeDirection.UNKNOWN);
        boolean shootingInventory = false;
        if (itemShot == null) {
            shootingInventory = true;
            itemShot = getPayloadEntity();
            if (itemShot instanceof EntityItem) {
                inventory[0] = null;
                if (getUpgrades(ItemMachineUpgrade.UPGRADE_BLOCK_TRACKER) > 0) {
                    trackedItems.add((EntityItem) itemShot);
                }
            } else {
                inventory[0].stackSize--;
                if (inventory[0].stackSize <= 0)
                    inventory[0] = null;
            }
        } else if (itemShot instanceof EntityPlayer) {
            EntityPlayerMP entityplayermp = (EntityPlayerMP) itemShot;
            if (entityplayermp.playerNetServerHandler.func_147362_b().isChannelOpen()) {
                entityplayermp.setPositionAndUpdate(xCoord + 0.5D, yCoord + 1.8D, zCoord + 0.5D);
            }
        }
        if (itemShot.isRiding()) {
            itemShot.mountEntity((Entity) null);
        }
        itemShot.setPosition(xCoord + 0.5D, yCoord + 1.8D, zCoord + 0.5D);
        NetworkHandler.sendToAllAround(new PacketSetEntityMotion(itemShot, velocity[0], velocity[1], velocity[2]), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64));
        if (itemShot instanceof EntityFireball) {
            velocity[0] *= 0.05D;
            velocity[1] *= 0.05D;
            velocity[2] *= 0.05D;
        }
        itemShot.motionX = velocity[0];
        itemShot.motionY = velocity[1];
        itemShot.motionZ = velocity[2];
        itemShot.onGround = false;
        itemShot.isCollided = false;
        itemShot.isCollidedHorizontally = false;
        itemShot.isCollidedVertically = false;
        if (itemShot instanceof EntityLivingBase)
            ((EntityLivingBase) itemShot).setJumping(true);
        if (shootingInventory && !worldObj.isRemote)
            worldObj.spawnEntityInWorld(itemShot);
        for (int i = 0; i < 10; i++) {
            double velX = velocity[0] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
            double velY = velocity[1] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
            double velZ = velocity[2] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
            NetworkHandler.sendToAllAround(new PacketSpawnParticle("largesmoke", xCoord + 0.5D, yCoord + 0.7D, zCoord + 0.5D, velX, velY, velZ), worldObj);
        }
        NetworkHandler.sendToAllAround(new PacketPlaySound(Sounds.CANNON_SOUND, xCoord, yCoord, zCoord, 1.0F, rand.nextFloat() / 4F + 0.75F, true), worldObj);
        return true;
    } else {
        return false;
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) PacketSpawnParticle(pneumaticCraft.common.network.PacketSpawnParticle) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint) PacketPlaySound(pneumaticCraft.common.network.PacketPlaySound) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityItem(net.minecraft.entity.item.EntityItem) PacketSetEntityMotion(pneumaticCraft.common.network.PacketSetEntityMotion) EntityFireball(net.minecraft.entity.projectile.EntityFireball)

Example 84 with EntityPlayerMP

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

the class DummyContainer method handleDummyClick.

public void handleDummyClick(Slot slot, int slotId, ItemStack currentlyEquippedStack, int mouseButton, int isShift, EntityPlayer entityplayer) {
    if (slot instanceof FluidSlot) {
        if (currentlyEquippedStack != null) {
            FluidStack liquidId = FluidContainerRegistry.getFluidForFilledItem(currentlyEquippedStack);
            if (liquidId != null) {
                FluidIdentifier ident = FluidIdentifier.get(liquidId);
                if (mouseButton == 0) {
                    if (ident == null) {
                        slot.putStack(null);
                    } else {
                        slot.putStack(ident.getItemIdentifier().unsafeMakeNormalStack(1));
                    }
                } else {
                    slot.putStack(null);
                }
                return;
            }
            FluidIdentifier ident = FluidIdentifier.get(currentlyEquippedStack);
            if (ident != null) {
                if (mouseButton == 0) {
                    slot.putStack(ident.getItemIdentifier().unsafeMakeNormalStack(1));
                } else {
                    slot.putStack(null);
                }
                return;
            }
        }
        FluidIdentifier ident = null;
        if (slot.getStack() != null) {
            ident = FluidIdentifier.get(ItemIdentifier.get(slot.getStack()));
        }
        if (ident == null) {
            if (MainProxy.isClient(entityplayer.getEntityWorld())) {
                MainProxy.proxy.openFluidSelectGui(slotId);
            }
        }
        slot.putStack(null);
        return;
    }
    if (slot instanceof ColorSlot) {
        MinecraftColor equipped = MinecraftColor.getColor(currentlyEquippedStack);
        MinecraftColor color = MinecraftColor.getColor(slot.getStack());
        if (MinecraftColor.BLANK.equals(equipped)) {
            if (mouseButton == 0) {
                color = color.getNext();
            } else if (mouseButton == 1) {
                color = color.getPrev();
            } else {
                color = MinecraftColor.BLANK;
            }
            slot.putStack(color.getItemStack());
        } else {
            if (mouseButton == 1) {
                slot.putStack(MinecraftColor.BLANK.getItemStack());
            } else {
                slot.putStack(equipped.getItemStack());
            }
        }
        if (entityplayer instanceof EntityPlayerMP && MainProxy.isServer(entityplayer.worldObj)) {
            ((EntityPlayerMP) entityplayer).sendSlotContents(this, slotId, slot.getStack());
        }
        return;
    }
    if (slot instanceof DummySlot) {
        ((DummySlot) slot).setRedirectCall(true);
    }
    if (currentlyEquippedStack == null) {
        if (slot.getStack() != null && mouseButton == 1) {
            ItemStack tstack = slot.getStack();
            if (isShift == 1) {
                tstack.stackSize = Math.min(slot.getSlotStackLimit(), tstack.stackSize * 2);
            } else {
                tstack.stackSize /= 2;
                if (tstack.stackSize <= 0) {
                    tstack = null;
                }
            }
            slot.putStack(tstack);
        } else {
            slot.putStack(null);
        }
        if (slot instanceof DummySlot) {
            ((DummySlot) slot).setRedirectCall(false);
        }
        return;
    }
    if (!slot.getHasStack()) {
        ItemStack tstack = currentlyEquippedStack.copy();
        if (mouseButton == 1) {
            tstack.stackSize = 1;
        }
        if (tstack.stackSize > slot.getSlotStackLimit()) {
            tstack.stackSize = slot.getSlotStackLimit();
        }
        slot.putStack(tstack);
        if (slot instanceof DummySlot) {
            ((DummySlot) slot).setRedirectCall(false);
        }
        return;
    }
    ItemIdentifier currentItem = ItemIdentifier.get(currentlyEquippedStack);
    ItemIdentifier slotItem = ItemIdentifier.get(slot.getStack());
    if (currentItem.equals(slotItem)) {
        ItemStack tstack = slot.getStack();
        // Do manual shift-checking to play nice with NEI
        int counter = isShift == 1 ? 10 : 1;
        if (mouseButton == 1) {
            if (tstack.stackSize + counter <= slot.getSlotStackLimit()) {
                tstack.stackSize += counter;
            } else {
                tstack.stackSize = slot.getSlotStackLimit();
            }
            slot.putStack(tstack);
        } else if (mouseButton == 0) {
            tstack.stackSize -= counter;
            if (tstack.stackSize <= 0) {
                tstack = null;
            }
            slot.putStack(tstack);
        }
        if (slot instanceof DummySlot) {
            ((DummySlot) slot).setRedirectCall(false);
        }
        return;
    }
    ItemStack tstack = currentlyEquippedStack.copy();
    if (tstack.stackSize > slot.getSlotStackLimit()) {
        tstack.stackSize = slot.getSlotStackLimit();
    }
    slot.putStack(tstack);
    if (slot instanceof DummySlot) {
        ((DummySlot) slot).setRedirectCall(false);
    }
    return;
}
Also used : MinecraftColor(logisticspipes.utils.MinecraftColor) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) FluidStack(net.minecraftforge.fluids.FluidStack) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemStack(net.minecraft.item.ItemStack)

Example 85 with EntityPlayerMP

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

the class DummyContainer method slotClick.

/**
	 * Clone/clear itemstacks for items
	 */
@Override
public ItemStack slotClick(int slotId, int mouseButton, int isShift, EntityPlayer entityplayer) {
    lastClicked = System.currentTimeMillis();
    if (slotId < 0) {
        return superSlotClick(slotId, mouseButton, isShift, entityplayer);
    }
    Slot slot = (Slot) inventorySlots.get(slotId);
    //debug dump
    if (LPConstants.DEBUG && slot != null) {
        ItemStack stack = slot.getStack();
        if (stack != null) {
            ItemIdentifier.get(stack).debugDumpData(entityplayer.worldObj.isRemote);
        }
    }
    if (slot == null || (!(slot instanceof DummySlot) && !(slot instanceof UnmodifiableSlot) && !(slot instanceof FluidSlot) && !(slot instanceof ColorSlot) && !(slot instanceof HandelableSlot))) {
        ItemStack stack1 = superSlotClick(slotId, mouseButton, isShift, entityplayer);
        ItemStack stack2 = slot.getStack();
        if (stack2 != null && stack2.getItem() == LogisticsPipes.ModuleItem) {
            if (entityplayer instanceof EntityPlayerMP && MainProxy.isServer(entityplayer.worldObj)) {
                ((EntityPlayerMP) entityplayer).sendSlotContents(this, slotId, stack2);
            }
        }
        return stack1;
    }
    InventoryPlayer inventoryplayer = entityplayer.inventory;
    ItemStack currentlyEquippedStack = inventoryplayer.getItemStack();
    // we get a leftclick *and* a doubleclick message if there's a doubleclick with no item on the pointer, filter it out
    if (currentlyEquippedStack == null && isShift == 6) {
        return currentlyEquippedStack;
    }
    if (slot instanceof HandelableSlot) {
        overrideMCAntiSend = true;
        if (currentlyEquippedStack == null) {
            inventoryplayer.setItemStack(((HandelableSlot) slot).getProvidedStack());
            return null;
        }
        return currentlyEquippedStack;
    }
    if (slot instanceof UnmodifiableSlot) {
        return currentlyEquippedStack;
    }
    handleDummyClick(slot, slotId, currentlyEquippedStack, mouseButton, isShift, entityplayer);
    return currentlyEquippedStack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Slot(net.minecraft.inventory.Slot) IFuzzySlot(logisticspipes.interfaces.IFuzzySlot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)124 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 Entity (net.minecraft.entity.Entity)15 ItemStack (net.minecraft.item.ItemStack)15 TileEntity (net.minecraft.tileentity.TileEntity)13 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)13 EntityLivingBase (net.minecraft.entity.EntityLivingBase)12 BlockPos (net.minecraft.util.math.BlockPos)9 WrongUsageException (net.minecraft.command.WrongUsageException)7 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)7 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6 Block (net.minecraft.block.Block)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)6 World (net.minecraft.world.World)6 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)5 MinecraftServer (net.minecraft.server.MinecraftServer)5 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)4 TextComponentString (net.minecraft.util.text.TextComponentString)4 WorldServer (net.minecraft.world.WorldServer)4