use of net.minecraftforge.event.entity.player.PlayerDestroyItemEvent in project ArsMagica2 by Mithion.
the class SlotMagiciansWorkbenchCrafting method doStandardDecrement.
private void doStandardDecrement(IInventory inventory, ItemStack itemstack1, int i) {
if (itemstack1.getItem().hasContainerItem(itemstack1)) {
ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1);
if (itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage()) {
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, itemstack2));
itemstack2 = null;
}
if (itemstack2 != null) {
inventory.setInventorySlotContents(i, itemstack2);
} else {
inventory.decrStackSize(i, 1);
}
} else {
inventory.decrStackSize(i, 1);
}
}
use of net.minecraftforge.event.entity.player.PlayerDestroyItemEvent in project BetterStorage by copygirl.
the class InventoryCraftingStation method craftSlot.
private ItemStack craftSlot(ItemStack stack, IRecipeInput requiredInput, EntityPlayer player, boolean simulate) {
if (simulate)
stack = stack.copy();
ContainerInfo containerInfo = new ContainerInfo();
requiredInput.craft(stack, containerInfo);
ItemStack containerItem = ItemStack.copyItemStack(containerInfo.getContainerItem());
boolean removeStack = false;
if (stack.stackSize <= 0) {
// Item stack is depleted.
removeStack = true;
} else if (stack.getItem().isDamageable() && (stack.getItemDamage() > stack.getMaxDamage())) {
// Item stack is destroyed.
removeStack = true;
if (player != null)
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
}
// to either null, or the container item.
if (removeStack) {
if (!containerInfo.doesLeaveCrafting()) {
stack = containerItem;
containerItem = null;
} else
stack = null;
}
if ((containerItem != null) && !simulate) {
// Try to add the container item to the internal storage, or spawn the item in the world.
if (!InventoryUtils.tryAddItemToInventory(containerItem, new InventoryStacks(contents), true) && (entity != null))
WorldUtils.spawnItem(entity.getWorldObj(), entity.xCoord + 0.5, entity.yCoord + 0.5, entity.zCoord + 0.5, containerItem);
}
return stack;
}
use of net.minecraftforge.event.entity.player.PlayerDestroyItemEvent in project PneumaticCraft by MineMaarten.
the class FMPPlacementListener method place.
public static boolean place(EntityPlayer player, World world) {
MovingObjectPosition hit = RayTracer.reTrace(world, player);
if (hit == null)
return false;
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
ItemStack held = player.getHeldItem();
PartPressureTube part = null;
if (held == null)
return false;
Block heldBlock = Block.getBlockFromItem(held.getItem());
if (heldBlock == Blockss.pressureTube) {
part = new PartPressureTube();
} else if (heldBlock == Blockss.advancedPressureTube) {
part = new PartAdvancedPressureTube();
}
if (part == null)
return false;
if (// attempt to use block activated like normal and tell the server the right stuff
world.isRemote && !player.isSneaking()) {
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
if (!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z)) {
player.swingItem();
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x, (float) f.y, (float) f.z));
return true;
}
}
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
if (tile == null || !tile.canAddPart(part)) {
pos = pos.offset(hit.sideHit);
tile = TileMultipart.getOrConvertTile(world, pos);
if (tile == null || !tile.canAddPart(part))
return false;
}
if (!world.isRemote) {
TileMultipart.addPart(world, pos, part);
world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, Blockss.pressureTube.stepSound.func_150496_b(), (Blockss.pressureTube.stepSound.getVolume() + 1.0F) / 2.0F, Blockss.pressureTube.stepSound.getPitch() * 0.8F);
if (!player.capabilities.isCreativeMode) {
held.stackSize--;
if (held.stackSize == 0) {
player.inventory.mainInventory[player.inventory.currentItem] = null;
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
}
}
} else {
player.swingItem();
NetworkHandler.sendToServer(new PacketFMPPlacePart());
}
return true;
}
Aggregations