Fix some issues in the digitizer #57

Merged
BlakeRain merged 2 commits from BlakeRain/utamacraft:main into main 2024-01-29 17:51:07 +00:00

View File

@ -17,11 +17,10 @@ import net.banutama.utamacraft.integrations.computercraft.peripheral.digitizer.D
import net.banutama.utamacraft.integrations.computercraft.peripheral.digitizer.DigitizedItem; import net.banutama.utamacraft.integrations.computercraft.peripheral.digitizer.DigitizedItem;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
public class DigitizerPeripheral extends BasePeripheral { public class DigitizerPeripheral extends BasePeripheral {
public static final String PERIPHERAL_TYPE = "digitizier"; public static final String PERIPHERAL_TYPE = "digitizer";
protected DigitizerPeripheral(BasePeripheralOwner owner) { protected DigitizerPeripheral(BasePeripheralOwner owner) {
super(PERIPHERAL_TYPE, owner); super(PERIPHERAL_TYPE, owner);
@ -170,6 +169,9 @@ public class DigitizerPeripheral extends BasePeripheral {
return MethodResult.of(null, "No digitized item with ID " + id.toString()); return MethodResult.of(null, "No digitized item with ID " + id.toString());
} }
// Store the name of the digitized item for later
var itemName = ForgeRegistries.ITEMS.getKey(digitizedItem.itemStack.getItem());
// This is the number of items available in the digitized item stack. // This is the number of items available in the digitized item stack.
var available = digitizedItem.itemStack.getCount(); var available = digitizedItem.itemStack.getCount();
@ -254,7 +256,16 @@ public class DigitizerPeripheral extends BasePeripheral {
result.put("cost", cost); result.put("cost", cost);
result.put("materializeCost", materializeCost); result.put("materializeCost", materializeCost);
result.put("refreshCost", refreshCost); result.put("refreshCost", refreshCost);
result.put("item", digitizedItem.describeItem(gameTime));
{
// Here we need to overwrite the stored `name` property with the original item
// name. This is because the `describeItem` method will return a `name` property
// of `minecraft:air` if we've successfully materialized the entire digitized
// stack.
var item = digitizedItem.describeItem(gameTime);
item.put("name", itemName.toString());
result.put("item", item);
}
return MethodResult.of(result); return MethodResult.of(result);
} }