-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/folk/sisby/tinkerers_smithing/mixin/IngredientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package folk.sisby.tinkerers_smithing.mixin; | ||
|
||
import folk.sisby.tinkerers_smithing.TinkerersSmithing; | ||
import it.unimi.dsi.fastutil.ints.IntArrayList; | ||
import it.unimi.dsi.fastutil.ints.IntList; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.recipe.Ingredient; | ||
import net.minecraft.util.registry.Registry; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(Ingredient.class) | ||
public class IngredientMixin { | ||
@Unique private boolean isFootgun() { | ||
if (Registry.ITEM.streamTagsAndEntries().toList().isEmpty()) { | ||
TinkerersSmithing.LOGGER.error("[Tinkerer's Smithing] Cowardly refusing to access ingredient while tags are unloaded", new IllegalStateException("An ingredient was accessed before item tags are loaded - This would normally break all tag recipes! Please report this to the mod in the trace below.")); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Inject(method = "getMatchingStacks", at = @At("HEAD"), cancellable = true) | ||
public void getMatchingStacks(CallbackInfoReturnable<ItemStack[]> cir) { | ||
if (isFootgun()) { | ||
cir.setReturnValue(new ItemStack[]{}); | ||
cir.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "test(Lnet/minecraft/item/ItemStack;)Z", at = @At("HEAD"), cancellable = true) | ||
public void test(CallbackInfoReturnable<Boolean> cir) { | ||
if (isFootgun()) { | ||
cir.setReturnValue(false); | ||
cir.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "getMatchingItemIds", at = @At("HEAD"), cancellable = true) | ||
public void getMatchingItemIds(CallbackInfoReturnable<IntList> cir) { | ||
if (isFootgun()) { | ||
cir.setReturnValue(new IntArrayList()); | ||
cir.cancel(); | ||
} | ||
} | ||
|
||
@Inject(method = "write", at = @At("HEAD"), cancellable = true) | ||
public void write(PacketByteBuf buf, CallbackInfo ci) { | ||
if (isFootgun()) { | ||
buf.writeVarInt(0); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters