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();
}
}
}
}
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();
}
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;
}
}
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;
}
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;
}
Aggregations