Compare commits

...
2 Commits
Author SHA1 Message Date
Dream-Master 00c31a6158 bump version 2020-03-27 21:27:04 +01:00
bartimaeusnek 5db5b712ce Fixed Mutation Coniditons (#5)
+ reduced usage of reflexion
+ inlined code

Signed-off-by: bartimaeusnek <[email protected]>
2020-03-27 14:12:42 +01:00
7 changed files with 16 additions and 28 deletions

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@ mcversion=1.7.10
forgeversion=10.13.4.1614-1.7.10
version_major=4
version_minor=2
version_patch=25
version_patch=26
@@ -15,6 +15,8 @@ import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IJubilanceProvider;
import forestry.core.utils.BlockUtil;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -52,7 +54,7 @@ public class JubilanceRequiresResource implements IJubilanceProvider {
(TileEntity tile) -> (tile instanceof IBeeHousing)
);
return blockRequired.equals(stk); //this way to prevent NPEs
return InventoryUtil.isItemEqual(blockRequired, stk, true, true); //ffs dont compare itemsstacks with equal >_> and why tf didnt i got this until i debugged it? im getting old..
}
}
@@ -15,6 +15,8 @@ import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import forestry.api.genetics.IMutationCondition;
import forestry.core.utils.BlockUtil;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
@@ -51,7 +53,7 @@ public class MutationConditionRequiresResource implements IMutationCondition {
(TileEntity tile) -> (tile instanceof IBeeHousing)
);
return blockRequired.equals(stk) ? 1f : 0f;
return InventoryUtil.isItemEqual(blockRequired, stk, true, true) ? 1 : 0;
}
@Override
@@ -231,16 +231,14 @@ public abstract class BlockUtil {
}
private static Class<? extends Block> BW_MetaGenerated_WerkstoffBlocksClass;
private static Method getDamage;
private static Block BWBlocks;
private static boolean bw = Loader.isModLoaded("bartworks");
static {
if (bw)
try {
BW_MetaGenerated_WerkstoffBlocksClass = (Class<? extends Block>) Class.forName("com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_WerkstoffBlocks");
getDamage = Class.forName("com.github.bartimaeusnek.bartworks.system.material.BW_MetaGenerated_Blocks").getMethod("getDamageValue", World.class, int.class, int.class, int.class);
BWBlocks = (Block) Class.forName("com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader").getField("BWBlocks").get(null);
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException | NoSuchMethodException e) {
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
@@ -257,12 +255,7 @@ public abstract class BlockUtil {
block = world.getBlock(x, y - depth, z);
if (bw && BW_MetaGenerated_WerkstoffBlocksClass.isInstance(block)) {
try {
return new ItemStack(BWBlocks, 1, (Integer) getDamage.invoke(block, world, x, y - depth, z));
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
return new ItemStack(BWBlocks, 1, block.getDamageValue(world, x, y - depth, z));
}
return new ItemStack(block, 1, world.getBlockMetadata(x, y - depth, z));
@@ -105,10 +105,7 @@ public abstract class InventoryUtil {
if (a.getItemDamage() != b.getItemDamage()) {
return false;
}
if (a.stackTagCompound != null && !a.stackTagCompound.equals(b.stackTagCompound)) {
return false;
}
return true;
return a.stackTagCompound == null || a.stackTagCompound.equals(b.stackTagCompound);
}
/**
@@ -137,9 +134,7 @@ public abstract class InventoryUtil {
if (isWildcard(a) || isWildcard(b)) {
return true;
}
if (a.getItemDamage() != b.getItemDamage()) {
return false;
}
return a.getItemDamage() == b.getItemDamage();
}
return true;
}
@@ -157,8 +157,8 @@ public abstract class ItemStackUtil {
int reqCount = 0;
for (ItemStack offer : condensedOffered) {
if (isCraftingEquivalent(req, offer, oreDictionary, craftingTools) && (matchTags ? ItemStack.areItemStackTagsEqual(req, offer) : true)) {
int stackCount = (int) Math.floor(offer.stackSize / req.stackSize);
if (isCraftingEquivalent(req, offer, oreDictionary, craftingTools) && (!matchTags || ItemStack.areItemStackTagsEqual(req, offer))) {
int stackCount = (int) Math.floor( (float) offer.stackSize / (float) req.stackSize);
reqCount = Math.max(reqCount, stackCount);
}
}
@@ -316,7 +316,7 @@ public abstract class ItemStackUtil {
public static ItemStack copyWithRandomSize(ItemStack template, int max, Random rand) {
int size = rand.nextInt(max);
ItemStack created = template.copy();
created.stackSize = size <= 0 ? 1 : size > created.getMaxStackSize() ? created.getMaxStackSize() : size;
created.stackSize = size <= 0 ? 1 : Math.min(size, created.getMaxStackSize());
return created;
}
@@ -35,9 +35,7 @@ public abstract class ModUtil {
VersionRange versionRange = VersionParser.parseRange(versionRangeString);
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(modname, versionRange);
if (!requiredVersion.containsVersion(modVersion)) {
return false;
}
return requiredVersion.containsVersion(modVersion);
}
return true;
@@ -69,9 +67,7 @@ public abstract class ModUtil {
DefaultArtifactVersion givenVersion = new DefaultArtifactVersion(apiName, apiVersionString);
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(apiName, versionRange);
if (!requiredVersion.containsVersion(givenVersion)) {
return false;
}
return requiredVersion.containsVersion(givenVersion);
}
return true;