Fix a bunch of things assuming the player only has main hand. Closes #424

This commit is contained in:
Vincent Lee committed 2016-08-05 18:31:44 -05:00
1 parent 8eccfad65e
commit acd5cce7ce
15 files changed
+45 -39

No files matched your search

@@ -179,7 +179,7 @@ public class BlockAltar extends BlockMod implements ILexiconable {
} else if(stack != null && stack.getItem() == Items.BUCKET && (tile.hasWater || tile.hasLava) && !Botania.gardenOfGlassLoaded) {
ItemStack bucket = tile.hasLava ? new ItemStack(Items.LAVA_BUCKET) : new ItemStack(Items.WATER_BUCKET);
if(stack.stackSize == 1)
player.inventory.setInventorySlotContents(player.inventory.currentItem, bucket);
player.setHeldItem(hand, bucket);
else {
if(!player.inventory.addItemStackToInventory(bucket))
player.dropItem(bucket, false);
@@ -119,7 +119,7 @@ public class BlockSparkChanger extends BlockMod implements ILexiconable {
pstack.stackSize--;
if(pstack.stackSize == 0)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
return true;
}
@@ -93,7 +93,7 @@ public class BlockBrewery extends BlockMod implements ILexiconable, IWandHUD {
InventoryHelper.withdrawFromInventory(brew, player);
} else {
if(stack != null)
return brew.addItem(player, stack);
return brew.addItem(player, stack, hand);
}
return false;
}
@@ -117,7 +117,7 @@ public class BlockEnchanter extends BlockMod implements IWandable, ILexiconable,
if(enchanter.itemToEnchant == null) {
if(stackEnchantable) {
enchanter.itemToEnchant = stack.copy();
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
enchanter.sync();
}
} else if(enchanter.stage == TileEnchanter.State.IDLE) {
@@ -122,7 +122,7 @@ public class BlockPrism extends BlockMod implements IManaTrigger, ILexiconable,
if(lens == null && isHeldItemLens) {
if(!player.capabilities.isCreativeMode)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
prism.getItemHandler().setStackInSlot(0, heldItem.copy());
prism.markDirty();
@@ -83,7 +83,7 @@ public class BlockRuneAltar extends BlockMod implements IWandable, ILexiconable
altar.trySetLastRecipe(player);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(altar);
} else if(stack != null) {
boolean result = altar.addItem(player, stack);
boolean result = altar.addItem(player, stack, hand);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(altar);
return result;
}
@@ -158,7 +158,7 @@ public class BlockSpreader extends BlockMod implements IWandable, IWandHUD, ILex
if(lens == null && isHeldItemLens) {
if (!player.capabilities.isCreativeMode)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
spreader.getItemHandler().setStackInSlot(0, heldItem.copy());
spreader.markDirty();
@@ -174,7 +174,7 @@ public class BlockSpreader extends BlockMod implements IWandable, IWandHUD, ILex
spreader.paddingColor = heldItem.getItemDamage();
heldItem.stackSize--;
if(heldItem.stackSize == 0)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
} else if(heldItem == null && spreader.paddingColor != -1 && lens == null) {
ItemStack pad = new ItemStack(Blocks.WOOL, 1, spreader.paddingColor);
if(!player.inventory.addItemStackToInventory(pad))
@@ -58,7 +58,7 @@ public class BlockTerraPlate extends BlockMod implements ILexiconable {
if(player == null || !player.capabilities.isCreativeMode) {
stack.stackSize--;
if(stack.stackSize == 0 && player != null)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
}
ItemStack target = stack.copy();
@@ -16,6 +16,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import vazkii.botania.api.BotaniaAPI;
@@ -31,6 +32,7 @@ import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.*;
import java.util.List;
@@ -44,7 +46,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver {
int manaLastTick = 0;
public int signal = 0;
public boolean addItem(EntityPlayer player, ItemStack stack) {
public boolean addItem(@Nullable EntityPlayer player, ItemStack stack, @Nullable EnumHand hand) {
if(recipe != null || stack == null || stack.getItem() instanceof IBrewItem && ((IBrewItem) stack.getItem()).getBrew(stack) != null && ((IBrewItem) stack.getItem()).getBrew(stack) != BotaniaAPI.fallbackBrew || itemHandler.getStackInSlot(0) == null != stack.getItem() instanceof IBrewContainer)
return false;
@@ -60,7 +62,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver {
if(player == null || !player.capabilities.isCreativeMode) {
stack.stackSize--;
if(stack.stackSize == 0 && player != null)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
}
break;
@@ -99,7 +101,7 @@ public class TileBrewery extends TileSimpleInventory implements IManaReceiver {
for(EntityItem item : items)
if(!item.isDead && item.getEntityItem() != null) {
ItemStack stack = item.getEntityItem();
if(addItem(null, stack) && stack.stackSize == 0)
if(addItem(null, stack, null) && stack.stackSize == 0)
item.setDead();
}
}
@@ -19,6 +19,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import org.lwjgl.opengl.GL11;
@@ -35,6 +36,7 @@ import vazkii.botania.common.core.helper.Vector3;
import vazkii.botania.common.item.ModItems;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@@ -53,7 +55,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver
List<ItemStack> lastRecipe = null;
int recipeKeepTicks = 0;
public boolean addItem(EntityPlayer player, ItemStack stack) {
public boolean addItem(@Nullable EntityPlayer player, ItemStack stack, @Nullable EnumHand hand) {
if(cooldown > 0 || stack.getItem() == ModItems.twigWand || stack.getItem() == ModItems.lexicon)
return false;
@@ -61,7 +63,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver
if(player == null || !player.capabilities.isCreativeMode) {
stack.stackSize--;
if(stack.stackSize == 0 && player != null)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
player.setHeldItem(hand, null);
}
EntityItem item = new EntityItem(worldObj, getPos().getX() + 0.5, getPos().getY() + 1, getPos().getZ() + 0.5, new ItemStack(ModBlocks.livingrock));
@@ -111,7 +113,7 @@ public class TileRuneAltar extends TileSimpleInventory implements IManaReceiver
for(EntityItem item : items)
if(!item.isDead && item.getEntityItem() != null && item.getEntityItem().getItem() != Item.getItemFromBlock(ModBlocks.livingrock)) {
ItemStack stack = item.getEntityItem();
if(addItem(null, stack) && stack.stackSize == 0)
if(addItem(null, stack, null) && stack.stackSize == 0)
item.setDead();
}
}
@@ -2,10 +2,10 @@
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
*
* File Created @ [Jun 27, 2014, 2:41:19 AM (GMT)]
*/
package vazkii.botania.common.item;
@@ -54,7 +54,7 @@ public class ItemBottledMana extends ItemMod {
setMaxDamage(6);
}
public void effect(EntityLivingBase living, int id) {
public void effect(ItemStack stack, EntityLivingBase living, int id) {
switch(id) {
case 0 : { // Random motion
living.motionX = (Math.random() - 0.5) * 3;
@@ -98,13 +98,14 @@ public class ItemBottledMana extends ItemMod {
case 7 : { // All your inventory is belong to us
if(!living.worldObj.isRemote && living instanceof EntityPlayer) {
EntityPlayer player = ((EntityPlayer) living);
for(int i = 0; i < player.inventory.getSizeInventory(); i++)
if(i != player.inventory.currentItem) {
ItemStack stackAt = player.inventory.getStackInSlot(i);
for(int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack stackAt = player.inventory.getStackInSlot(i);
if(stackAt != stack) {
if(stackAt != null)
player.entityDropItem(stackAt, 0);
player.inventory.setInventorySlotContents(i, null);
}
}
}
break;
@@ -189,15 +190,13 @@ public class ItemBottledMana extends ItemMod {
}
@Override
public void onUpdate(ItemStack par1ItemStack, World world, Entity par3Entity, int par4, boolean par5) {
getSeed(par1ItemStack);
public void onUpdate(ItemStack par1ItemStack, World world, Entity par3Entity, int par4, boolean par5) {}
private void randomEffect(EntityLivingBase player, ItemStack stack) {
effect(stack, player, new Random(getSeed(stack)).nextInt(16));
}
public void randomEffect(EntityLivingBase player, ItemStack stack) {
effect(player, new Random(getSeed(stack)).nextInt(16));
}
long getSeed(ItemStack stack) {
private long getSeed(ItemStack stack) {
long seed = ItemNBTHelper.getLong(stack, TAG_SEED, -1);
if(seed == -1)
return randomSeed(stack);
@@ -57,20 +57,22 @@ public abstract class ItemBauble extends ItemMod implements IBauble, ICosmeticAt
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack par1ItemStack, World world, EntityPlayer player, EnumHand hand) {
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
if(!EntityDoppleganger.isTruePlayer(player))
return ActionResult.newResult(EnumActionResult.FAIL, par1ItemStack);
return ActionResult.newResult(EnumActionResult.FAIL, stack);
if(canEquip(par1ItemStack, player)) {
ItemStack toEquip = stack.copy();
toEquip.stackSize = 1;
if(canEquip(toEquip, player)) {
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
for(int i = 0; i < baubles.getSizeInventory(); i++) {
if(baubles.isItemValidForSlot(i, par1ItemStack)) {
if(baubles.isItemValidForSlot(i, toEquip)) {
ItemStack stackInSlot = baubles.getStackInSlot(i);
if(stackInSlot == null || ((IBauble) stackInSlot.getItem()).canUnequip(stackInSlot, player)) {
if(!world.isRemote) {
baubles.setInventorySlotContents(i, par1ItemStack.copy());
if(!player.capabilities.isCreativeMode)
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
baubles.setInventorySlotContents(i, toEquip);
stack.stackSize--;
}
if(stackInSlot != null) {
@@ -83,7 +85,7 @@ public abstract class ItemBauble extends ItemMod implements IBauble, ICosmeticAt
}
}
return ActionResult.newResult(EnumActionResult.PASS, par1ItemStack);
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
@Override
@@ -16,6 +16,7 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;
import vazkii.botania.api.item.ISortableTool;
import vazkii.botania.api.item.ISortableTool.ToolType;
@@ -78,7 +79,7 @@ public class ItemSwapRing extends ItemBauble {
}
if(bestSlot != -1) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, bestTool);
player.setHeldItem(EnumHand.MAIN_HAND, bestTool);
player.inventory.setInventorySlotContents(bestSlot, currentStack);
}
}
@@ -78,7 +78,7 @@ public class ItemManaResource extends ItemMod implements IFlowerComponent, IElve
stack.stackSize--;
if(stack.stackSize == 0)
event.getEntityPlayer().inventory.setInventorySlotContents(event.getEntityPlayer().inventory.currentItem, null);
event.getEntityPlayer().setHeldItem(event.getHand(), null);
event.getWorld().playSound(null, event.getPos(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.5F, 1F);
event.setCanceled(true);
@@ -92,7 +92,7 @@ public final class SkyblockWorldEvents {
--equipped.stackSize;
if(equipped.stackSize <= 0)
event.getEntityPlayer().inventory.setInventorySlotContents(event.getEntityPlayer().inventory.currentItem, new ItemStack(ModItems.waterBowl));
event.getEntityPlayer().setHeldItem(event.getHand(), new ItemStack(ModItems.waterBowl));
else event.getEntityPlayer().dropItem(new ItemStack(ModItems.waterBowl), false);
}
}