mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 04:09:40 +00:00
Prevent Botania's bauble item tooltips breaking in some situations (#19)
* Fixed bauble tooltips breaking with certain bindings Prevents some items tooltips and in-inventory rendering from breaking if the Baubles key is unbound, bound to a mouse button, or an abnormal keyboard key. * update BS Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
84e758e450
commit
54f79398b1
13 files changed
+867
-648
No files matched your search
@@ -1,26 +1,26 @@
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.api.corporea;
|
||||
|
||||
public class CorporeaRequest {
|
||||
public Object matcher;
|
||||
public boolean checkNBT;
|
||||
public int count;
|
||||
public int foundItems = 0;
|
||||
public int extractedItems = 0;
|
||||
|
||||
public CorporeaRequest(Object matcher, boolean checkNBT, int count) {
|
||||
super();
|
||||
this.matcher = matcher;
|
||||
this.checkNBT = checkNBT;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.api.corporea;
|
||||
|
||||
public class CorporeaRequest {
|
||||
public Object matcher;
|
||||
public boolean checkNBT;
|
||||
public int count;
|
||||
public int foundItems = 0;
|
||||
public int extractedItems = 0;
|
||||
|
||||
public CorporeaRequest(Object matcher, boolean checkNBT, int count) {
|
||||
super();
|
||||
this.matcher = matcher;
|
||||
this.checkNBT = checkNBT;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +1,57 @@
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.api.corporea;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This interface wraps IInventory corporea works with in order to provide
|
||||
* compatibility with different storage mods.
|
||||
*
|
||||
*/
|
||||
public interface IWrappedInventory {
|
||||
|
||||
/**
|
||||
* Break encapsulation and exposes original inventory.
|
||||
*/
|
||||
IInventory getWrappedObject();
|
||||
|
||||
/**
|
||||
* Counts items in the inventory matching the request
|
||||
*
|
||||
* @param request
|
||||
* - specifies what should be found
|
||||
* @return List of ItemStack, individual stacks may exceed maxStackSize for
|
||||
* purposes of counting huge amounts. To get final count requestor
|
||||
* should sum stackSize of all stacks.
|
||||
*/
|
||||
List<ItemStack> countItems(CorporeaRequest request);
|
||||
|
||||
/**
|
||||
* Convenience method for accessing spark over inventory
|
||||
*/
|
||||
ICorporeaSpark getSpark();
|
||||
|
||||
/**
|
||||
* Extracts items matching request from the inventory.<br/>
|
||||
* {@link CorporeaRequest#count} is updated to reflect how many items are
|
||||
* yet to be extracted.<br/>
|
||||
* {@link CorporeaRequest#foundItems} and
|
||||
* {@link CorporeaRequest#extractedItems} are updated to reflect how many
|
||||
* items were found and extracted.
|
||||
*
|
||||
* @param request
|
||||
* @return List of ItemStacks to be delivered to the destination.
|
||||
*/
|
||||
List<ItemStack> extractItems(CorporeaRequest request);
|
||||
}
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.api.corporea;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* This interface wraps IInventory corporea works with in order to provide
|
||||
* compatibility with different storage mods.
|
||||
*
|
||||
*/
|
||||
public interface IWrappedInventory {
|
||||
|
||||
/**
|
||||
* Break encapsulation and exposes original inventory.
|
||||
*/
|
||||
IInventory getWrappedObject();
|
||||
|
||||
/**
|
||||
* Counts items in the inventory matching the request
|
||||
*
|
||||
* @param request
|
||||
* - specifies what should be found
|
||||
* @return List of ItemStack, individual stacks may exceed maxStackSize for
|
||||
* purposes of counting huge amounts. To get final count requestor
|
||||
* should sum stackSize of all stacks.
|
||||
*/
|
||||
List<ItemStack> countItems(CorporeaRequest request);
|
||||
|
||||
/**
|
||||
* Convenience method for accessing spark over inventory
|
||||
*/
|
||||
ICorporeaSpark getSpark();
|
||||
|
||||
/**
|
||||
* Extracts items matching request from the inventory.<br/>
|
||||
* {@link CorporeaRequest#count} is updated to reflect how many items are
|
||||
* yet to be extracted.<br/>
|
||||
* {@link CorporeaRequest#foundItems} and
|
||||
* {@link CorporeaRequest#extractedItems} are updated to reflect how many
|
||||
* items were found and extracted.
|
||||
*
|
||||
* @param request
|
||||
* @return List of ItemStacks to be delivered to the destination.
|
||||
*/
|
||||
List<ItemStack> extractItems(CorporeaRequest request);
|
||||
}
|
||||
@@ -17,11 +17,11 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import vazkii.botania.client.core.handler.ClientTickHandler;
|
||||
@@ -243,7 +243,7 @@ public final class RenderHelper {
|
||||
KeyBinding[] keys = Minecraft.getMinecraft().gameSettings.keyBindings;
|
||||
for(KeyBinding otherKey : keys)
|
||||
if(otherKey.getKeyDescription().equals(keyName)) {
|
||||
key = Keyboard.getKeyName(otherKey.getKeyCode());
|
||||
key = GameSettings.getKeyDisplayString(otherKey.getKeyCode());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+136
-136
@@ -1,136 +1,136 @@
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
import vazkii.botania.api.corporea.CorporeaRequest;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
/**
|
||||
* Wrapper for StorageDrawers compatibility.
|
||||
*
|
||||
*/
|
||||
public class WrappedDeepStorage extends WrappedInventoryBase {
|
||||
|
||||
private static boolean checkedInterface = false;
|
||||
private static boolean deepStoragePresent = false;
|
||||
|
||||
private IDeepStorageUnit inv;
|
||||
|
||||
private WrappedDeepStorage(IDeepStorageUnit inv, ICorporeaSpark spark) {
|
||||
this.inv = inv;
|
||||
this.spark = spark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getWrappedObject() {
|
||||
return (IInventory) inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> countItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> extractItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, true);
|
||||
}
|
||||
|
||||
private List<ItemStack> iterateOverStacks(CorporeaRequest request, boolean doit) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
boolean removedAny = false;
|
||||
|
||||
ItemStack prototype = inv.getStoredItemType();
|
||||
if(prototype == null) {
|
||||
// for the case of barrel without contents set
|
||||
return stacks;
|
||||
}
|
||||
int storedCount = prototype.stackSize;
|
||||
|
||||
// WARNING: this code is very similar in all implementations of
|
||||
// IWrappedInventory - keep it synch
|
||||
// this code is also near duplicate to WrappedStorageDrawers - keep it
|
||||
// synchronized
|
||||
if(isMatchingItemStack(request.matcher, request.checkNBT, prototype)) {
|
||||
int rem = Math.min(storedCount, request.count == -1 ? storedCount : request.count);
|
||||
|
||||
if(rem > 0) {
|
||||
ItemStack copy = prototype.copy();
|
||||
copy.stackSize = rem;
|
||||
if(doit) {
|
||||
stacks.addAll(breakDownBigStack(copy));
|
||||
} else {
|
||||
stacks.add(copy);
|
||||
}
|
||||
}
|
||||
|
||||
request.foundItems += storedCount;
|
||||
request.extractedItems += rem;
|
||||
|
||||
if(doit && rem > 0) {
|
||||
decreaseStoredCount(inv, rem);
|
||||
|
||||
removedAny = true;
|
||||
if(spark != null)
|
||||
spark.onItemExtracted(prototype);
|
||||
}
|
||||
if(request.count != -1)
|
||||
request.count -= rem;
|
||||
}
|
||||
if(removedAny) {
|
||||
// inv.markDirtyIfNeeded();
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
private void decreaseStoredCount(IDeepStorageUnit inventory, int rem) {
|
||||
inventory.setStoredItemCount(inventory.getStoredItemType().stackSize - rem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link WrappedDeepStorage} if specified inv can be wrapped.
|
||||
*
|
||||
* @return wrapped inventory or null if it has incompatible type.
|
||||
*/
|
||||
public static IWrappedInventory wrap(IInventory inv, ICorporeaSpark spark) {
|
||||
if(!isDeepStorageNeeded()) {
|
||||
return null;
|
||||
}
|
||||
return inv instanceof IDeepStorageUnit ? new WrappedDeepStorage((IDeepStorageUnit) inv, spark) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks for presence of Deep Storage API in the pack - if some
|
||||
* other mod provides IDeepStorageUnit, support for Deep Storage will be
|
||||
* used. This way we don't have to ship IDeepStorageUnit in Botania jar.
|
||||
*/
|
||||
private static boolean isDeepStorageNeeded() {
|
||||
if(!checkedInterface) {
|
||||
try {
|
||||
deepStoragePresent = (Class.forName("powercrystals.minefactoryreloaded.api.IDeepStorageUnit") != null);
|
||||
} catch (ClassNotFoundException e) {
|
||||
deepStoragePresent = false;
|
||||
}
|
||||
checkedInterface = true;
|
||||
FMLLog.log(Level.INFO, "[Botania] Corporea support for Deep Storage: %b", deepStoragePresent);
|
||||
}
|
||||
return deepStoragePresent;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
import vazkii.botania.api.corporea.CorporeaRequest;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
/**
|
||||
* Wrapper for StorageDrawers compatibility.
|
||||
*
|
||||
*/
|
||||
public class WrappedDeepStorage extends WrappedInventoryBase {
|
||||
|
||||
private static boolean checkedInterface = false;
|
||||
private static boolean deepStoragePresent = false;
|
||||
|
||||
private IDeepStorageUnit inv;
|
||||
|
||||
private WrappedDeepStorage(IDeepStorageUnit inv, ICorporeaSpark spark) {
|
||||
this.inv = inv;
|
||||
this.spark = spark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getWrappedObject() {
|
||||
return (IInventory) inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> countItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> extractItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, true);
|
||||
}
|
||||
|
||||
private List<ItemStack> iterateOverStacks(CorporeaRequest request, boolean doit) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
boolean removedAny = false;
|
||||
|
||||
ItemStack prototype = inv.getStoredItemType();
|
||||
if(prototype == null) {
|
||||
// for the case of barrel without contents set
|
||||
return stacks;
|
||||
}
|
||||
int storedCount = prototype.stackSize;
|
||||
|
||||
// WARNING: this code is very similar in all implementations of
|
||||
// IWrappedInventory - keep it synch
|
||||
// this code is also near duplicate to WrappedStorageDrawers - keep it
|
||||
// synchronized
|
||||
if(isMatchingItemStack(request.matcher, request.checkNBT, prototype)) {
|
||||
int rem = Math.min(storedCount, request.count == -1 ? storedCount : request.count);
|
||||
|
||||
if(rem > 0) {
|
||||
ItemStack copy = prototype.copy();
|
||||
copy.stackSize = rem;
|
||||
if(doit) {
|
||||
stacks.addAll(breakDownBigStack(copy));
|
||||
} else {
|
||||
stacks.add(copy);
|
||||
}
|
||||
}
|
||||
|
||||
request.foundItems += storedCount;
|
||||
request.extractedItems += rem;
|
||||
|
||||
if(doit && rem > 0) {
|
||||
decreaseStoredCount(inv, rem);
|
||||
|
||||
removedAny = true;
|
||||
if(spark != null)
|
||||
spark.onItemExtracted(prototype);
|
||||
}
|
||||
if(request.count != -1)
|
||||
request.count -= rem;
|
||||
}
|
||||
if(removedAny) {
|
||||
// inv.markDirtyIfNeeded();
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
private void decreaseStoredCount(IDeepStorageUnit inventory, int rem) {
|
||||
inventory.setStoredItemCount(inventory.getStoredItemType().stackSize - rem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link WrappedDeepStorage} if specified inv can be wrapped.
|
||||
*
|
||||
* @return wrapped inventory or null if it has incompatible type.
|
||||
*/
|
||||
public static IWrappedInventory wrap(IInventory inv, ICorporeaSpark spark) {
|
||||
if(!isDeepStorageNeeded()) {
|
||||
return null;
|
||||
}
|
||||
return inv instanceof IDeepStorageUnit ? new WrappedDeepStorage((IDeepStorageUnit) inv, spark) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks for presence of Deep Storage API in the pack - if some
|
||||
* other mod provides IDeepStorageUnit, support for Deep Storage will be
|
||||
* used. This way we don't have to ship IDeepStorageUnit in Botania jar.
|
||||
*/
|
||||
private static boolean isDeepStorageNeeded() {
|
||||
if(!checkedInterface) {
|
||||
try {
|
||||
deepStoragePresent = (Class.forName("powercrystals.minefactoryreloaded.api.IDeepStorageUnit") != null);
|
||||
} catch (ClassNotFoundException e) {
|
||||
deepStoragePresent = false;
|
||||
}
|
||||
checkedInterface = true;
|
||||
FMLLog.log(Level.INFO, "[Botania] Corporea support for Deep Storage: %b", deepStoragePresent);
|
||||
}
|
||||
return deepStoragePresent;
|
||||
}
|
||||
}
|
||||
@@ -1,92 +1,92 @@
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.corporea.CorporeaHelper;
|
||||
import vazkii.botania.api.corporea.CorporeaRequest;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
public class WrappedIInventory extends WrappedInventoryBase{
|
||||
|
||||
private IInventory inv;
|
||||
|
||||
private WrappedIInventory(IInventory inv, ICorporeaSpark spark) {
|
||||
this.inv = inv;
|
||||
this.spark = spark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getWrappedObject() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> countItems(CorporeaRequest request) {
|
||||
return iterateOverSlots(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> extractItems(CorporeaRequest request) {
|
||||
return iterateOverSlots(request, true);
|
||||
}
|
||||
|
||||
private List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
|
||||
boolean removedAny = false;
|
||||
for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
|
||||
if(!CorporeaHelper.isValidSlot(inv, i))
|
||||
continue;
|
||||
|
||||
ItemStack stackAt = inv.getStackInSlot(i);
|
||||
// WARNING: this code is very similar in all implementations of
|
||||
// IWrappedInventory - keep it synch
|
||||
if(isMatchingItemStack(request.matcher, request.checkNBT, stackAt)) {
|
||||
int rem = Math.min(stackAt.stackSize, request.count == -1 ? stackAt.stackSize : request.count);
|
||||
|
||||
if(rem > 0) {
|
||||
ItemStack copy = stackAt.copy();
|
||||
if(rem < copy.stackSize)
|
||||
copy.stackSize = rem;
|
||||
stacks.add(copy);
|
||||
}
|
||||
|
||||
request.foundItems += stackAt.stackSize;
|
||||
request.extractedItems += rem;
|
||||
|
||||
if(doit && rem > 0) {
|
||||
inv.decrStackSize(i, rem);
|
||||
removedAny = true;
|
||||
if(spark != null)
|
||||
spark.onItemExtracted(stackAt);
|
||||
}
|
||||
if(request.count != -1)
|
||||
request.count -= rem;
|
||||
}
|
||||
}
|
||||
|
||||
if(removedAny) {
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static IWrappedInventory wrap(IInventory inv, ICorporeaSpark spark) {
|
||||
return new WrappedIInventory(inv, spark);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.corporea.CorporeaHelper;
|
||||
import vazkii.botania.api.corporea.CorporeaRequest;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
public class WrappedIInventory extends WrappedInventoryBase{
|
||||
|
||||
private IInventory inv;
|
||||
|
||||
private WrappedIInventory(IInventory inv, ICorporeaSpark spark) {
|
||||
this.inv = inv;
|
||||
this.spark = spark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getWrappedObject() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> countItems(CorporeaRequest request) {
|
||||
return iterateOverSlots(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> extractItems(CorporeaRequest request) {
|
||||
return iterateOverSlots(request, true);
|
||||
}
|
||||
|
||||
private List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
|
||||
boolean removedAny = false;
|
||||
for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
|
||||
if(!CorporeaHelper.isValidSlot(inv, i))
|
||||
continue;
|
||||
|
||||
ItemStack stackAt = inv.getStackInSlot(i);
|
||||
// WARNING: this code is very similar in all implementations of
|
||||
// IWrappedInventory - keep it synch
|
||||
if(isMatchingItemStack(request.matcher, request.checkNBT, stackAt)) {
|
||||
int rem = Math.min(stackAt.stackSize, request.count == -1 ? stackAt.stackSize : request.count);
|
||||
|
||||
if(rem > 0) {
|
||||
ItemStack copy = stackAt.copy();
|
||||
if(rem < copy.stackSize)
|
||||
copy.stackSize = rem;
|
||||
stacks.add(copy);
|
||||
}
|
||||
|
||||
request.foundItems += stackAt.stackSize;
|
||||
request.extractedItems += rem;
|
||||
|
||||
if(doit && rem > 0) {
|
||||
inv.decrStackSize(i, rem);
|
||||
removedAny = true;
|
||||
if(spark != null)
|
||||
spark.onItemExtracted(stackAt);
|
||||
}
|
||||
if(request.count != -1)
|
||||
request.count -= rem;
|
||||
}
|
||||
}
|
||||
|
||||
if(removedAny) {
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static IWrappedInventory wrap(IInventory inv, ICorporeaSpark spark) {
|
||||
return new WrappedIInventory(inv, spark);
|
||||
}
|
||||
|
||||
}
|
||||
+52
-52
@@ -1,52 +1,52 @@
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.corporea.CorporeaHelper;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
public abstract class WrappedInventoryBase implements IWrappedInventory {
|
||||
|
||||
protected ICorporeaSpark spark;
|
||||
|
||||
@Override
|
||||
public ICorporeaSpark getSpark() {
|
||||
return spark;
|
||||
}
|
||||
|
||||
protected boolean isMatchingItemStack(Object matcher, boolean checkNBT, ItemStack stackAt) {
|
||||
return matcher instanceof ItemStack ? CorporeaHelper.stacksMatch((ItemStack) matcher, stackAt, checkNBT)
|
||||
: matcher instanceof String ? CorporeaHelper.stacksMatch(stackAt, (String) matcher) : false;
|
||||
}
|
||||
|
||||
protected Collection<? extends ItemStack> breakDownBigStack(ItemStack stack) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
int additionalStacks = stack.stackSize / stack.getMaxStackSize();
|
||||
int lastStackSize = stack.stackSize % stack.getMaxStackSize();
|
||||
if(additionalStacks > 0) {
|
||||
ItemStack fullStack = stack.copy();
|
||||
fullStack.stackSize = stack.getMaxStackSize();
|
||||
for (int i = 0; i < additionalStacks; i++) {
|
||||
stacks.add(fullStack.copy());
|
||||
}
|
||||
}
|
||||
ItemStack lastStack = stack.copy();
|
||||
lastStack.stackSize = lastStackSize;
|
||||
stacks.add(lastStack);
|
||||
|
||||
return stacks;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.corporea.CorporeaHelper;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
public abstract class WrappedInventoryBase implements IWrappedInventory {
|
||||
|
||||
protected ICorporeaSpark spark;
|
||||
|
||||
@Override
|
||||
public ICorporeaSpark getSpark() {
|
||||
return spark;
|
||||
}
|
||||
|
||||
protected boolean isMatchingItemStack(Object matcher, boolean checkNBT, ItemStack stackAt) {
|
||||
return matcher instanceof ItemStack ? CorporeaHelper.stacksMatch((ItemStack) matcher, stackAt, checkNBT)
|
||||
: matcher instanceof String ? CorporeaHelper.stacksMatch(stackAt, (String) matcher) : false;
|
||||
}
|
||||
|
||||
protected Collection<? extends ItemStack> breakDownBigStack(ItemStack stack) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
int additionalStacks = stack.stackSize / stack.getMaxStackSize();
|
||||
int lastStackSize = stack.stackSize % stack.getMaxStackSize();
|
||||
if(additionalStacks > 0) {
|
||||
ItemStack fullStack = stack.copy();
|
||||
fullStack.stackSize = stack.getMaxStackSize();
|
||||
for (int i = 0; i < additionalStacks; i++) {
|
||||
stacks.add(fullStack.copy());
|
||||
}
|
||||
}
|
||||
ItemStack lastStack = stack.copy();
|
||||
lastStack.stackSize = lastStackSize;
|
||||
stacks.add(lastStack);
|
||||
|
||||
return stacks;
|
||||
}
|
||||
}
|
||||
+113
-113
@@ -1,113 +1,113 @@
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.corporea.CorporeaRequest;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
/**
|
||||
* Wrapper for StorageDrawers compatibility.
|
||||
*
|
||||
*/
|
||||
public class WrappedStorageDrawers extends WrappedInventoryBase {
|
||||
|
||||
private IDrawerGroup inv;
|
||||
|
||||
private WrappedStorageDrawers(IDrawerGroup inv, ICorporeaSpark spark) {
|
||||
this.inv = inv;
|
||||
this.spark = spark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getWrappedObject() {
|
||||
return (IInventory) inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> countItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> extractItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, true);
|
||||
}
|
||||
|
||||
private List<ItemStack> iterateOverStacks(CorporeaRequest request, boolean doit) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
boolean removedAny = false;
|
||||
|
||||
for(int i = 0; i < inv.getDrawerCount(); i++) {
|
||||
IDrawer drawer = inv.getDrawer(i);
|
||||
if(drawer == null) {
|
||||
continue;
|
||||
}
|
||||
ItemStack prototype = drawer.getStoredItemPrototype();
|
||||
int storedCount = drawer.getStoredItemCount();
|
||||
|
||||
// WARNING: this code is very similar in all implementations of
|
||||
// IWrappedInventory - keep it synch
|
||||
// also this code is near duplicate to WrappedDeepStorage - keep it
|
||||
// synchronized
|
||||
if(isMatchingItemStack(request.matcher, request.checkNBT, prototype)) {
|
||||
int rem = Math.min(storedCount, request.count == -1 ? storedCount : request.count);
|
||||
|
||||
if(rem > 0) {
|
||||
ItemStack copy = prototype.copy();
|
||||
copy.stackSize = rem;
|
||||
if(doit) {
|
||||
stacks.addAll(breakDownBigStack(copy));
|
||||
} else {
|
||||
stacks.add(copy);
|
||||
}
|
||||
}
|
||||
|
||||
request.foundItems += storedCount;
|
||||
request.extractedItems += rem;
|
||||
|
||||
if(doit && rem > 0) {
|
||||
decreaseStoredCount(drawer, rem);
|
||||
|
||||
removedAny = true;
|
||||
if(spark != null)
|
||||
spark.onItemExtracted(prototype);
|
||||
}
|
||||
if(request.count != -1)
|
||||
request.count -= rem;
|
||||
}
|
||||
}
|
||||
if(removedAny) {
|
||||
inv.markDirtyIfNeeded();
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
private void decreaseStoredCount(IDrawer drawer, int rem) {
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() - rem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link WrappedStorageDrawers} if specified inv can be wrapped.
|
||||
*
|
||||
* @return wrapped inventory or null if it has incompatible type.
|
||||
*/
|
||||
public static IWrappedInventory wrap(IInventory inv, ICorporeaSpark spark) {
|
||||
return inv instanceof IDrawerGroup ? new WrappedStorageDrawers((IDrawerGroup) inv, spark) : null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This class was created by <Vindex>. 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
|
||||
*
|
||||
*/
|
||||
package vazkii.botania.common.integration.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.corporea.CorporeaRequest;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.api.corporea.IWrappedInventory;
|
||||
|
||||
/**
|
||||
* Wrapper for StorageDrawers compatibility.
|
||||
*
|
||||
*/
|
||||
public class WrappedStorageDrawers extends WrappedInventoryBase {
|
||||
|
||||
private IDrawerGroup inv;
|
||||
|
||||
private WrappedStorageDrawers(IDrawerGroup inv, ICorporeaSpark spark) {
|
||||
this.inv = inv;
|
||||
this.spark = spark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getWrappedObject() {
|
||||
return (IInventory) inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> countItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> extractItems(CorporeaRequest request) {
|
||||
return iterateOverStacks(request, true);
|
||||
}
|
||||
|
||||
private List<ItemStack> iterateOverStacks(CorporeaRequest request, boolean doit) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
boolean removedAny = false;
|
||||
|
||||
for(int i = 0; i < inv.getDrawerCount(); i++) {
|
||||
IDrawer drawer = inv.getDrawer(i);
|
||||
if(drawer == null) {
|
||||
continue;
|
||||
}
|
||||
ItemStack prototype = drawer.getStoredItemPrototype();
|
||||
int storedCount = drawer.getStoredItemCount();
|
||||
|
||||
// WARNING: this code is very similar in all implementations of
|
||||
// IWrappedInventory - keep it synch
|
||||
// also this code is near duplicate to WrappedDeepStorage - keep it
|
||||
// synchronized
|
||||
if(isMatchingItemStack(request.matcher, request.checkNBT, prototype)) {
|
||||
int rem = Math.min(storedCount, request.count == -1 ? storedCount : request.count);
|
||||
|
||||
if(rem > 0) {
|
||||
ItemStack copy = prototype.copy();
|
||||
copy.stackSize = rem;
|
||||
if(doit) {
|
||||
stacks.addAll(breakDownBigStack(copy));
|
||||
} else {
|
||||
stacks.add(copy);
|
||||
}
|
||||
}
|
||||
|
||||
request.foundItems += storedCount;
|
||||
request.extractedItems += rem;
|
||||
|
||||
if(doit && rem > 0) {
|
||||
decreaseStoredCount(drawer, rem);
|
||||
|
||||
removedAny = true;
|
||||
if(spark != null)
|
||||
spark.onItemExtracted(prototype);
|
||||
}
|
||||
if(request.count != -1)
|
||||
request.count -= rem;
|
||||
}
|
||||
}
|
||||
if(removedAny) {
|
||||
inv.markDirtyIfNeeded();
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
private void decreaseStoredCount(IDrawer drawer, int rem) {
|
||||
drawer.setStoredItemCount(drawer.getStoredItemCount() - rem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link WrappedStorageDrawers} if specified inv can be wrapped.
|
||||
*
|
||||
* @return wrapped inventory or null if it has incompatible type.
|
||||
*/
|
||||
public static IWrappedInventory wrap(IInventory inv, ICorporeaSpark spark) {
|
||||
return inv instanceof IDrawerGroup ? new WrappedStorageDrawers((IDrawerGroup) inv, spark) : null;
|
||||
}
|
||||
}
|
||||
@@ -94,8 +94,9 @@ public abstract class ItemBauble extends ItemMod implements IBauble, ICosmeticAt
|
||||
|
||||
String key = vazkii.botania.client.core.helper.RenderHelper.getKeyDisplayString("Baubles Inventory");
|
||||
|
||||
if(key != null)
|
||||
if(key != null && !key.equals("NONE")) {
|
||||
addStringToTooltip(StatCollector.translateToLocal("botania.baubletooltip").replaceAll("%key%", key), par3List);
|
||||
}
|
||||
|
||||
ItemStack cosmetic = getCosmeticItem(par1ItemStack);
|
||||
if(cosmetic != null)
|
||||
|
||||
Reference in new issue
Block a user