fixed radiated foods kinda

This commit is contained in:
2026-02-16 11:16:53 +01:00
parent befa4406e4
commit 5b5fdd8cd1
6 changed files with 148 additions and 41 deletions

View File

@@ -7,12 +7,11 @@ import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -32,44 +31,33 @@ public class CraftingScreenHandlerMixin {
CraftingResultInventory resultInventory,
CallbackInfo ci) {
if (world.isClient) return;
ItemStack resultStack = ItemStack.EMPTY;
boolean hasRadiated = false;
ItemStack foodStack = ItemStack.EMPTY;
// Check the crafting grid
for (int i = 0; i < craftingInventory.size(); i++) {
ItemStack stack = craftingInventory.getStack(i);
if (stack.isEmpty()) continue;
if (stack.getItem() instanceof RadiatedItem) {
hasRadiated = true;
} else if (stack.isFood()) {
foodStack = stack;
}
if (stack.getItem() instanceof RadiatedItem) hasRadiated = true;
else if (stack.isFood()) foodStack = stack;
}
// If we found a food + radiated item, make a new edible copy
if (hasRadiated && !foodStack.isEmpty()) {
resultStack = new ItemStack(foodStack.getItem()); // preserves the original Item and its FoodComponent
resultStack.setCount(1); // optional: set to 1
ItemStack resultStack = new ItemStack(foodStack.getItem());
resultStack.setCount(1);
resultStack.setNbt(foodStack.getNbt() != null ? foodStack.getNbt().copy() : null);
// Add our custom NBT to mark radiation
resultStack.getOrCreateNbt().putBoolean("Radiated", true);
resultStack.getOrCreateNbt().putInt("RadPixelX", player.getRandom().nextInt(16));
resultStack.getOrCreateNbt().putInt("RadPixelY", player.getRandom().nextInt(16));
resultInventory.setStack(0, resultStack);
handler.setPreviousTrackedSlot(0, resultStack);
if (player instanceof ServerPlayerEntity serverPlayer) {
serverPlayer.networkHandler.sendPacket(
new ScreenHandlerSlotUpdateS2CPacket(handler.syncId, handler.nextRevision(), 0, resultStack)
);
}
ci.cancel(); // prevent vanilla overwrite
}
// Set the crafting output
resultInventory.setStack(0, resultStack);
handler.setPreviousTrackedSlot(0, resultStack);
((ServerPlayerEntity) player).networkHandler.sendPacket(
new ScreenHandlerSlotUpdateS2CPacket(handler.syncId, handler.nextRevision(), 0, resultStack)
);
ci.cancel(); // prevent vanilla recipe overwrite
}
}

View File

@@ -0,0 +1,48 @@
package dev.tggamesyt.szar.mixin;
import dev.tggamesyt.szar.RadiatedItem;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.screen.CraftingScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.CraftingResultSlot;
import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(CraftingResultSlot.class)
public class CraftingScreenHandlerMixin2 {
@Inject(
method = "onTakeItem",
at = @At("HEAD")
)
private void onTakeRadiatedItem(PlayerEntity player, ItemStack stack, CallbackInfo ci) {
if (stack.hasNbt() && stack.getNbt().getBoolean("Radiated")) {
ScreenHandler handler = player.currentScreenHandler;
// Only modify the 2x2 or 3x3 crafting grid slots (1-9)
for (int i = 1; i <= 9; i++) {
if (i >= handler.slots.size()) break; // safety check for 2x2
Slot slot = handler.slots.get(i);
ItemStack slotStack = slot.getStack();
if (!slotStack.isEmpty()) {
// Halve and round up
int newCount = (slotStack.getCount() / 2);
slotStack.setCount(newCount);
slot.markDirty();
}
}
}
}
}

View File

@@ -0,0 +1,15 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
{
"tag": "minecraft:music_discs"
},
{
"item": "szar:epstein_files"
}
],
"result": {
"item": "szar:baiter",
"count": 1
}
}

View File

@@ -6,6 +6,7 @@
"mixins": [
"PlayerEntityMixin",
"CraftingScreenHandlerMixin",
"CraftingScreenHandlerMixin2",
"RadiatedItemMixin"
],
"injectors": {