Fixed issue #23 dank/null compat only uses one block at a time regardless of how many are placed.
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
package nl.requios.effortlessbuilding.compatibility;
|
package nl.requios.effortlessbuilding.compatibility;
|
||||||
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemBlock;
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraftforge.fml.common.Loader;
|
import net.minecraftforge.fml.common.Loader;
|
||||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
@@ -63,9 +65,9 @@ public class CompatHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Dank Null
|
//Dank Null
|
||||||
if(proxyItem == dankNullItem) {
|
if (proxyItem == dankNullItem) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
if(proxy.hasTagCompound() && proxy.getTagCompound().hasKey("selectedIndex"))
|
if (proxy.hasTagCompound() && proxy.getTagCompound().hasKey("selectedIndex"))
|
||||||
index = proxy.getTagCompound().getInteger("selectedIndex");
|
index = proxy.getTagCompound().getInteger("selectedIndex");
|
||||||
return proxy.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
|
return proxy.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
|
||||||
}
|
}
|
||||||
@@ -75,14 +77,14 @@ public class CompatHelper {
|
|||||||
|
|
||||||
public static ItemStack getItemBlockByState(ItemStack stack, IBlockState state) {
|
public static ItemStack getItemBlockByState(ItemStack stack, IBlockState state) {
|
||||||
Item blockItem = Item.getItemFromBlock(state.getBlock());
|
Item blockItem = Item.getItemFromBlock(state.getBlock());
|
||||||
if(stack.getItem() instanceof ItemBlock)
|
if (stack.getItem() instanceof ItemBlock)
|
||||||
return stack;
|
return stack;
|
||||||
else if(stack.getItem() instanceof ItemRandomizerBag) {
|
else if (stack.getItem() instanceof ItemRandomizerBag) {
|
||||||
IItemHandler bagInventory = ItemRandomizerBag.getBagInventory(stack);
|
IItemHandler bagInventory = ItemRandomizerBag.getBagInventory(stack);
|
||||||
return ItemRandomizerBag.findStack(bagInventory, blockItem);
|
return ItemRandomizerBag.findStack(bagInventory, blockItem);
|
||||||
} else if(stack.getItem() == dankNullItem) {
|
} else if (stack.getItem() == dankNullItem) {
|
||||||
int index = itemHandlerSlotForItem(stack, blockItem);
|
int index = itemHandlerSlotForItem(stack, blockItem);
|
||||||
if(index >= 0)
|
if (index >= 0)
|
||||||
return stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
|
return stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
|
||||||
}
|
}
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
@@ -90,8 +92,11 @@ public class CompatHelper {
|
|||||||
|
|
||||||
// Handle IItemHandler slot stacks not being modifiable. We must call IItemHandler#extractItem,
|
// Handle IItemHandler slot stacks not being modifiable. We must call IItemHandler#extractItem,
|
||||||
// because the ItemStack returned by IItemHandler#getStackInSlot isn't modifiable.
|
// because the ItemStack returned by IItemHandler#getStackInSlot isn't modifiable.
|
||||||
public static void shrinkStack(ItemStack origStack, ItemStack curStack) {
|
public static void shrinkStack(ItemStack origStack, ItemStack curStack, EntityPlayer player) {
|
||||||
if(origStack.getItem() == dankNullItem) {
|
//Hacky way to get the origstack, because given origStack is itemblock stack and never a proxy
|
||||||
|
origStack = player.getHeldItem(EnumHand.MAIN_HAND);
|
||||||
|
|
||||||
|
if (origStack.getItem() == dankNullItem) {
|
||||||
int index = itemHandlerSlotForItem(origStack, curStack.getItem());
|
int index = itemHandlerSlotForItem(origStack, curStack.getItem());
|
||||||
origStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).extractItem(index, 1, false);
|
origStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).extractItem(index, 1, false);
|
||||||
} else
|
} else
|
||||||
@@ -100,10 +105,10 @@ public class CompatHelper {
|
|||||||
|
|
||||||
private static int itemHandlerSlotForItem(ItemStack stack, Item blockItem) {
|
private static int itemHandlerSlotForItem(ItemStack stack, Item blockItem) {
|
||||||
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||||
for(int i = 0; i < handler.getSlots(); i++) {
|
for (int i = 0; i < handler.getSlots(); i++) {
|
||||||
ItemStack ref = handler.getStackInSlot(i);
|
ItemStack ref = handler.getStackInSlot(i);
|
||||||
if(ref.getItem() instanceof ItemBlock)
|
if (ref.getItem() instanceof ItemBlock)
|
||||||
if(ref.getItem() == blockItem)
|
if (ref.getItem() == blockItem)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ public class ReachHelper {
|
|||||||
public static int getMaxBlocksPlacedAtOnce(EntityPlayer player) {
|
public static int getMaxBlocksPlacedAtOnce(EntityPlayer player) {
|
||||||
if (player.isCreative()) return 1000000;
|
if (player.isCreative()) return 1000000;
|
||||||
return MathHelper.ceil(Math.pow(getMaxReach(player), 1.6));
|
return MathHelper.ceil(Math.pow(getMaxReach(player), 1.6));
|
||||||
//Level 0: 90
|
//Level 0: 121
|
||||||
//Level 1: 353
|
//Level 1: 523
|
||||||
//Level 2: 1000
|
//Level 2: 1585
|
||||||
//Level 3: 2828
|
//Level 3: 4805
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxBlocksPerAxis(EntityPlayer player) {
|
public static int getMaxBlocksPerAxis(EntityPlayer player) {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class SurvivalHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!player.isCreative() && Block.getBlockFromItem(itemstack.getItem()) == block) {
|
if (!player.isCreative() && Block.getBlockFromItem(itemstack.getItem()) == block) {
|
||||||
CompatHelper.shrinkStack(origstack, itemstack);
|
CompatHelper.shrinkStack(origstack, itemstack, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user