Skip to content

Commit

Permalink
fix NPE in PatternDetail hashcode()
Browse files Browse the repository at this point in the history
  • Loading branch information
reobf committed Apr 2, 2024
1 parent d27e65f commit 5392b42
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ catch (Exception ignored) {

// Pulls version first from the VERSION env and then git tag
String identifiedVersion = null
String versionOverride = '0.0.6'
String versionOverride = '0.0.7'
try {
// Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty
if (versionOverride == null) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/reobf/proghatches/eucrafting/PartEUSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ public void reset() {

}


@Override
public ItemStack getCrafterIcon() {

return new ItemStack(MyMod.eu_source_part).setStackDisplayName(this.voltage+"V");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package reobf.proghatches.eucrafting;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles.Lookup;
import static reobf.proghatches.eucrafting.TileCraftingMinimiumEUTile.Scope.*;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.TileEvent;
import appeng.tile.crafting.TileCraftingTile;
import appeng.tile.events.TileEventType;

public class TileCraftingMinimiumEUTile extends TileCraftingTile{
public static class Scope{
public static void setScope(Lookup lup){
scope=lup;
try {
isComplete = scope.findGetter(CraftingCPUCluster.class,"isComplete", boolean.class);
} catch (Exception e) {

throw new AssertionError(e);
}
};
public static Lookup scope;
public static MethodHandle isComplete;
}


public CraftingCPUCluster getCraftingCluster() {
return (CraftingCPUCluster) this.getCluster();
}
@TileEvent(TileEventType .TICK)
public void tick(){try {
CraftingCPUCluster cluster = getCraftingCluster();
if(cluster==null)return;
if(cluster.getRemainingOperations()==0)return;

isComplete.invoke(cluster);



} catch (Throwable e) {e.printStackTrace();}


}



}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -325,6 +326,9 @@ public int hashCode() {
final ItemStack extraOut0;
public WrappedPatternDetail(ICraftingPatternDetails i,ItemStack extraIn,
ItemStack extraOut){
Objects.requireNonNull(extraIn);
Objects.requireNonNull(extraOut);
Objects.requireNonNull(i);
if(i.isCraftable()){ throw new IllegalArgumentException("workbench crafting");}
original=i;
this.extraIn=AEItemStack.create(extraIn);extraIn0=extraIn;
Expand Down Expand Up @@ -412,6 +416,9 @@ public void setPriority(int priority) {
public static class PatternDetail implements ICraftingPatternDetails {

public PatternDetail(ItemStack in, ItemStack out) {
Objects.requireNonNull(in);
Objects.requireNonNull(out);

this.in = in;
this.out = out;
i = new IAEItemStack[] { AEApi.instance().storage().createItemStack(in) };
Expand Down Expand Up @@ -496,13 +503,13 @@ public ItemStack getOutput(InventoryCrafting craftingInv, World world) {

@Override
public int getPriority() {
// TODO Auto-generated method stub

return Integer.MAX_VALUE;
}

@Override
public void setPriority(int priority) {
// TODO Auto-generated method stub


}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,5 +665,12 @@ public void onFacingChange() {
public boolean isPowered() {
return getProxy() != null && getProxy().isPowered();
}
@Override
public ItemStack getCrafterIcon() {
ItemStack is = this.getMachineCraftingIcon();
return is==null?
new ItemStack(GregTech_API.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID()):
is;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ public void provideCrafting(ICraftingProviderHelper craftingTracker) {

public static class CircuitProviderPatternDetial implements ICraftingPatternDetails {
@Nonnull
private ItemStack out;
final private ItemStack out;
@Nonnull
final int hash;
@Override
public boolean equals(Object obj) {
if(obj ==null){return false;}
Expand All @@ -362,14 +364,18 @@ public boolean equals(Object obj) {
@Override
public int hashCode() {
if(out==null)return 0;
return out.stackTagCompound.hashCode()^
return
hash;
/*
Optional.ofNullable(out.stackTagCompound).map(Object::hashCode).orElse(0)^
Integer.valueOf(Item.getIdFromItem(out.getItem())).hashCode()^
Integer.valueOf(out.getItemDamage());
Integer.valueOf(out.getItemDamage());*/
}


public CircuitProviderPatternDetial(ItemStack o) {
this.out = o;
public CircuitProviderPatternDetial(@Nonnull ItemStack o) {
if(o==null)throw new IllegalArgumentException("null");
this.out = o;hash=AEItemStack.create(out).hashCode()^0x1234abcd;
/*if(out ==null){
Thread.dumpStack();
Expand Down Expand Up @@ -543,5 +549,10 @@ public void loadNBTData(NBTTagCompound aNBT) {
}
getProxy().readFromNBT(aNBT);;
}
@Override
public ItemStack getCrafterIcon() {

return new ItemStack(GregTech_API.sBlockMachines, 1, getBaseMetaTileEntity().getMetaTileID());
}

}
1 change: 1 addition & 0 deletions src/main/java/reobf/proghatches/main/MyMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class MyMod {
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the
// GameRegistry." (Remove if not needed)
public void preInit(FMLPreInitializationEvent event) {
CraftingCPUCluster.class.getFields();
net.registerMessage(new OpenPartGuiMessage.Handler(), OpenPartGuiMessage.class, 0, Side.CLIENT);
proxy.preInit(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public List<String> getMixins() {
ArrayList<String> ret = new ArrayList<>();
ret.add("eucrafting."+"MixinWailaProvider");
ret.add("eucrafting."+"MixinRecipeStateDetect");
ret.add("eucrafting."+"MixinCpuClusterAccess");
//ret.add("eucrafting."+"MixinInterface");
//ret.add("eucrafting."+"MixinInterfacePart");
//ret.add("eucrafting."+"MixinUpgrade");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package reobf.proghatches.main.mixin.mixins.eucrafting;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Inject;

import appeng.me.cluster.implementations.CraftingCPUCluster;
import reobf.proghatches.eucrafting.TileCraftingMinimiumEUTile;
@Mixin(value = CraftingCPUCluster.class, remap = false, priority = 0)
public class MixinCpuClusterAccess {

static{ TileCraftingMinimiumEUTile.Scope.setScope(MethodHandles.lookup());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void displayAllReleventItems(List p_78018_1_) {
p_78018_1_.add(new ItemStack(MyMod.eu_source_part));
p_78018_1_.add(new ItemStack(MyMod.block_euinterface));
p_78018_1_.add(new ItemStack(MyMod.cover, 1, 2));
p_78018_1_.add(new ItemStack(MyMod.euinterface_p2p));


super.displayAllReleventItems(p_78018_1_);
Expand Down

0 comments on commit 5392b42

Please sign in to comment.