diff --git a/build.gradle b/build.gradle index 4253c5b..aee3af0 100644 --- a/build.gradle +++ b/build.gradle @@ -85,16 +85,15 @@ dependencies { // If you do not need Halplibe you can comment this line out or delete this line modImplementation "bta-halplibe:halplibe:${project.halplibe_version}" - modImplementation "ModMenu:ModMenu:2.0.0" + modImplementation "ModMenu:ModMenu:2.0.3" - modImplementation "sunsetutils:sunsetutils:1.9.1" - modImplementation "guidebookpp:guidebookpp:1.5.7" + modImplementation "catalyst:catalyst-core:1.1.1" implementation "org.slf4j:slf4j-api:1.8.0-beta4" implementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0" - implementation 'com.google.guava:guava:30.0-jre' - implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9' + implementation 'com.google.guava:guava:33.0.0-jre' + implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1' implementation("org.apache.commons:commons-lang3:3.12.0") diff --git a/gradle.properties b/gradle.properties index 67b3116..f45d1e3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,15 +1,15 @@ org.gradle.jvmargs=-Xmx2G # BTA -bta_version=1.7.7.0_02 +bta_version=7.1-pre1a # Loader -loader_version=0.14.19-babric.1-bta +loader_version=0.14.19-babric.3-bta # HalpLibe -halplibe_version=2.8.0 +halplibe_version=3.1.2 # Mod -mod_version=1.0.1 +mod_version=1.0.2 mod_group=sunsetsatellite mod_name=computers diff --git a/src/main/java/dan200/client/GuiComputer.java b/src/main/java/dan200/client/GuiComputer.java index 0fa7679..c6c7a50 100644 --- a/src/main/java/dan200/client/GuiComputer.java +++ b/src/main/java/dan200/client/GuiComputer.java @@ -28,24 +28,25 @@ public GuiComputer(TileEntityComputer tileentitycomputer) { this.m_rebootTimer = 0.0F; } - public void initGui() { - super.initGui(); + public void init() { + super.init(); Keyboard.enableRepeatEvents(true); this.m_terminateTimer = 0.0F; this.m_rebootTimer = 0.0F; } - public void onGuiClosed() { - super.onGuiClosed(); + public void onClosed() { + super.onClosed(); Keyboard.enableRepeatEvents(false); } - public boolean doesGuiPauseGame() { + @Override + public boolean pausesGame() { return false; } - public void updateScreen() { - super.updateScreen(); + public void tick() { + super.tick(); if (this.m_computer.isDestroyed()) { this.mc.displayGuiScreen(null); return; diff --git a/src/main/java/dan200/shared/BlockComputer.java b/src/main/java/dan200/shared/BlockComputer.java index 6a8b889..8f809ed 100644 --- a/src/main/java/dan200/shared/BlockComputer.java +++ b/src/main/java/dan200/shared/BlockComputer.java @@ -37,7 +37,7 @@ public class BlockComputer extends BlockTileEntityRotatable { public BlockComputer(String id, int i) { super(id, i, Material.stone); - setTickOnLoad(true); + setTicking(true); } public void onBlockAdded(World world, int i, int j, int k) { @@ -155,11 +155,12 @@ public int tickRate() { return 1; } - public void onBlockRemoval(World world, int i, int j, int k) { + @Override + public void onBlockRemoved(World world, int i, int j, int k, int data) { TileEntityComputer computer = (TileEntityComputer) world.getBlockTileEntity(i, j, k); if (computer != null) computer.destroy(); - super.onBlockRemoval(world, i, j, k); + super.onBlockRemoved(world, i, j, k, data); } @Override diff --git a/src/main/java/dan200/shared/BlockDiskDrive.java b/src/main/java/dan200/shared/BlockDiskDrive.java index 91d8998..b754ff0 100644 --- a/src/main/java/dan200/shared/BlockDiskDrive.java +++ b/src/main/java/dan200/shared/BlockDiskDrive.java @@ -33,12 +33,13 @@ public BlockDiskDrive(String id, int i) { super(id, i, Material.stone); } - public void onBlockRemoval(World world, int i, int j, int k) { + @Override + public void onBlockRemoved(World world, int i, int j, int k, int data) { TileEntityDiskDrive drive = (TileEntityDiskDrive) world.getBlockTileEntity(i, j, k); if (drive != null) { drive.ejectContents(true); } - super.onBlockRemoval(world, i, j, k); + super.onBlockRemoved(world, i, j, k, data); } @Override diff --git a/src/main/java/dan200/shared/ItemDisk.java b/src/main/java/dan200/shared/ItemDisk.java index f1c80c3..7a02ebc 100644 --- a/src/main/java/dan200/shared/ItemDisk.java +++ b/src/main/java/dan200/shared/ItemDisk.java @@ -11,9 +11,9 @@ import net.minecraft.core.item.Item; import net.minecraft.core.item.ItemStack; import net.minecraft.core.world.World; +import sunsetsatellite.catalyst.core.util.ICustomDescription; import sunsetsatellite.computers.Computers; import sunsetsatellite.computers.packets.PacketComputers; -import sunsetsatellite.sunsetutils.util.ICustomDescription; import java.io.*; import java.lang.ref.WeakReference; @@ -84,7 +84,7 @@ public Computer getOwner() { @Override public void execute() { - ItemDisk.loadLabels((World) labelWorld.get()); + //ItemDisk.loadLabels((World) labelWorld.get()); } }, null ); diff --git a/src/main/java/dan200/shared/TileEntityComputer.java b/src/main/java/dan200/shared/TileEntityComputer.java index 3263e65..25eb8b9 100644 --- a/src/main/java/dan200/shared/TileEntityComputer.java +++ b/src/main/java/dan200/shared/TileEntityComputer.java @@ -41,7 +41,7 @@ public void validate() { if (Computers.isMultiplayerClient()) { PacketComputers packet = new PacketComputers(); packet.packetType = 5; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord}; + packet.dataInt = new int[]{this.x, this.y, this.z}; Computers.sendToServer(packet); } } @@ -66,13 +66,13 @@ public boolean isDestroyed() { /* // WARNING - Removed try catching itself - possible behaviour change. */ - public void updateEntity() { + public void tick() { double dt = 0.05; if (!Computers.isMultiplayerClient()) { PacketComputers packet; this.m_computer.advance(dt); if (this.m_computer.pollChanged()) { - Computers.notifyBlockChange(this.worldObj, this.xCoord, this.yCoord, this.zCoord, Computers.computer.id); + Computers.notifyBlockChange(this.worldObj, this.x, this.y, this.z, Computers.computer.id); if (Computers.isMultiplayerServer()) { packet = this.createOutputChangedPacket(); Computers.sendToAllPlayers(packet); @@ -126,7 +126,7 @@ public void keyTyped(char ch, int key) { } else { PacketComputers packet = new PacketComputers(); packet.packetType = 2; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord, key}; + packet.dataInt = new int[]{this.x, this.y, this.z, key}; packet.dataString = new String[]{"" + ch}; Computers.sendToServer(packet); } @@ -138,7 +138,7 @@ public void terminate() { } else { PacketComputers packet = new PacketComputers(); packet.packetType = 6; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord}; + packet.dataInt = new int[]{this.x, this.y, this.z}; Computers.sendToServer(packet); } } @@ -149,7 +149,7 @@ public void reboot() { } else { PacketComputers packet = new PacketComputers(); packet.packetType = 9; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord}; + packet.dataInt = new int[]{this.x, this.y, this.z}; Computers.sendToServer(packet); } } @@ -160,7 +160,7 @@ public void shutdown() { } else { PacketComputers packet = new PacketComputers(); packet.packetType = 12; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord}; + packet.dataInt = new int[]{this.x, this.y, this.z}; Computers.sendToServer(packet); } } @@ -233,13 +233,13 @@ public void playRecord(String record) { if (Computers.isMultiplayerServer()) { PacketComputers packet = new PacketComputers(); packet.packetType = 7; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord}; + packet.dataInt = new int[]{this.x, this.y, this.z}; if (record != null) { packet.dataString = new String[]{record}; } Computers.sendToAllPlayers(packet); } else { - this.worldObj.playRecord(record, this.xCoord, this.yCoord, this.zCoord); + this.worldObj.playRecord(record, this.x, this.y, this.z); } } @@ -252,9 +252,9 @@ private void tryEjectDisk(int targetSide, int testSide, int i, int j, int k) { public void ejectDisk(int side) { if (!Computers.isMultiplayerClient()) { - int i = this.xCoord; - int j = this.yCoord; - int k = this.zCoord; + int i = this.x; + int j = this.y; + int k = this.z; int m = this.worldObj.getBlockMetadata(i, j, k); this.tryEjectDisk(side, BlockComputer.getLocalSide(0, m), i, j + 1, k); this.tryEjectDisk(side, BlockComputer.getLocalSide(1, m), i, j - 1, k); @@ -281,7 +281,7 @@ private PacketComputers createTerminalChangedPacket(boolean _includeAllText) { } PacketComputers packet = new PacketComputers(); packet.packetType = 3; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord, this.m_terminal.getCursorX(), this.m_terminal.getCursorY(), lineChangeMask}; + packet.dataInt = new int[]{this.x, this.y, this.z, this.m_terminal.getCursorX(), this.m_terminal.getCursorY(), lineChangeMask}; packet.dataString = new String[lineChangeCount]; int n = 0; for (int y = 0; y < this.m_terminal.getHeight(); ++y) { @@ -306,7 +306,7 @@ private PacketComputers createOutputChangedPacket() { if (!this.m_computer.getOutput(i)) continue; flags += 1 << i + 2; } - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord, flags, this.m_computer.getBundledOutput(0), this.m_computer.getBundledOutput(1), this.m_computer.getBundledOutput(2), this.m_computer.getBundledOutput(3), this.m_computer.getBundledOutput(3), this.m_computer.getBundledOutput(5)}; + packet.dataInt = new int[]{this.x, this.y, this.z, flags, this.m_computer.getBundledOutput(0), this.m_computer.getBundledOutput(1), this.m_computer.getBundledOutput(2), this.m_computer.getBundledOutput(3), this.m_computer.getBundledOutput(3), this.m_computer.getBundledOutput(5)}; return packet; } @@ -375,7 +375,7 @@ public void handlePacket(PacketComputers packet, EntityPlayer player) { this.m_clientData.output[i] = (flags & 1 << i + 2) > 0; this.m_clientData.bundledOutput[i] = packet.dataInt[4 + i]; } - Computers.notifyBlockChange(this.worldObj, this.xCoord, this.yCoord, this.zCoord, Computers.computer.id); + Computers.notifyBlockChange(this.worldObj, this.x, this.y, this.z, Computers.computer.id); break; } case 7: { diff --git a/src/main/java/dan200/shared/TileEntityDiskDrive.java b/src/main/java/dan200/shared/TileEntityDiskDrive.java index b55fa37..6b643b8 100644 --- a/src/main/java/dan200/shared/TileEntityDiskDrive.java +++ b/src/main/java/dan200/shared/TileEntityDiskDrive.java @@ -33,7 +33,7 @@ public void validate() { if (Computers.isMultiplayerClient()) { PacketComputers packet = new PacketComputers(); packet.packetType = 5; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord}; + packet.dataInt = new int[]{this.x, this.y, this.z}; Computers.sendToServer(packet); } } @@ -64,7 +64,7 @@ public void setInventorySlotContents(int i, ItemStack itemstack) { boolean hadDisk = this.hasDisk(); this.diskStack = itemstack; if (!Computers.isMultiplayerClient()) { - Computers.notifyBlockChange(this.worldObj, this.xCoord, this.yCoord, this.zCoord, Computers.diskDrive.id); + Computers.notifyBlockChange(this.worldObj, this.x, this.y, this.z, Computers.diskDrive.id); if (Computers.isMultiplayerServer()) { int newDiskLight = 0; if (this.hasAnything()) { @@ -109,10 +109,15 @@ public int getInventoryStackLimit() { @Override public boolean canInteractWith(EntityPlayer entityplayer) { - if (this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this) { + if (this.worldObj.getBlockTileEntity(this.x, this.y, this.z) != this) { return false; } - return entityplayer.distanceTo((double) this.xCoord + 0.5, (double) this.yCoord + 0.5, (double) this.zCoord + 0.5) <= 64.0; + return entityplayer.distanceTo((double) this.x + 0.5, (double) this.y + 0.5, (double) this.z + 0.5) <= 64.0; + } + + @Override + public void sortInventory() { + } public boolean hasAnything() { @@ -139,7 +144,7 @@ public void ejectContents(boolean destroyed) { int xOff = 0; int zOff = 0; if (!destroyed) { - int metaData = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); + int metaData = this.worldObj.getBlockMetadata(this.x, this.y, this.z); switch (metaData) { case 2: { zOff = -1; @@ -159,16 +164,16 @@ public void ejectContents(boolean destroyed) { } } } - double x = (double) this.xCoord + 0.5 + (double) xOff * 0.5; - double y = (double) this.yCoord + 0.75; - double z = (double) this.zCoord + 0.5 + (double) zOff * 0.5; + double x = (double) this.x + 0.5 + (double) xOff * 0.5; + double y = (double) this.y + 0.75; + double z = (double) this.z + 0.5 + (double) zOff * 0.5; EntityItem entityitem = new EntityItem(this.worldObj, x, y, z, disks); entityitem.xd = (double) xOff * 0.15; entityitem.yd = 0.0; entityitem.zd = (double) zOff * 0.15; this.worldObj.entityJoinedWorld(entityitem); if (!destroyed) { - this.worldObj.playSoundEffect(1000, this.xCoord, this.yCoord, this.zCoord, 0); + this.worldObj.playSoundEffect(1000, this.x, this.y, this.z, 0); } } } @@ -189,14 +194,14 @@ public String getAudioDiscRecordName() { return null; } - public void updateEntity() { + public void tick() { if (this.m_firstFrame) { if (!Computers.isMultiplayerClient()) { this.m_clientDiskLight = 0; if (this.hasAnything()) { this.m_clientDiskLight = this.hasDisk() ? 1 : 2; } - Computers.notifyBlockChange(this.worldObj, this.xCoord, this.yCoord, this.zCoord, Computers.diskDrive.id); + Computers.notifyBlockChange(this.worldObj, this.x, this.y, this.z, Computers.diskDrive.id); } this.m_firstFrame = false; } @@ -205,7 +210,7 @@ public void updateEntity() { private PacketComputers createDiskLightPacket() { PacketComputers packet = new PacketComputers(); packet.packetType = 8; - packet.dataInt = new int[]{this.xCoord, this.yCoord, this.zCoord, this.m_clientDiskLight}; + packet.dataInt = new int[]{this.x, this.y, this.z, this.m_clientDiskLight}; return packet; } @@ -229,7 +234,7 @@ public void handlePacket(PacketComputers packet, EntityPlayer player) { switch (packet.packetType) { case 8: { this.m_clientDiskLight = packet.dataInt[3]; - Computers.notifyBlockChange(this.worldObj, this.xCoord, this.yCoord, this.zCoord, Computers.diskDrive.id); + Computers.notifyBlockChange(this.worldObj, this.x, this.y, this.z, Computers.diskDrive.id); break; } } diff --git a/src/main/java/sunsetsatellite/computers/Computers.java b/src/main/java/sunsetsatellite/computers/Computers.java index e9740cf..78b9c5a 100644 --- a/src/main/java/sunsetsatellite/computers/Computers.java +++ b/src/main/java/sunsetsatellite/computers/Computers.java @@ -10,7 +10,12 @@ import net.minecraft.core.block.Block; import net.minecraft.core.block.entity.TileEntity; import net.minecraft.core.block.tag.BlockTags; -import net.minecraft.core.crafting.CraftingManager; +import net.minecraft.core.data.DataLoader; +import net.minecraft.core.data.registry.Registries; +import net.minecraft.core.data.registry.recipe.RecipeGroup; +import net.minecraft.core.data.registry.recipe.RecipeNamespace; +import net.minecraft.core.data.registry.recipe.RecipeSymbol; +import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCrafting; import net.minecraft.core.entity.player.EntityPlayer; import net.minecraft.core.item.Item; import net.minecraft.core.item.ItemStack; @@ -22,6 +27,7 @@ import turniplabs.halplibe.helper.BlockBuilder; import turniplabs.halplibe.helper.EntityHelper; import turniplabs.halplibe.helper.ItemHelper; +import turniplabs.halplibe.util.RecipeEntrypoint; import turniplabs.halplibe.util.TomlConfigHandler; import turniplabs.halplibe.util.toml.Toml; @@ -32,13 +38,16 @@ import java.util.stream.Collectors; -public class Computers implements ModInitializer { +public class Computers implements ModInitializer, RecipeEntrypoint { public static final String MOD_ID = "computers"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final TomlConfigHandler config; private static int availableBlockId = 1300; private static int availableItemId = 17300; + public static final RecipeNamespace COMPUTERS = new RecipeNamespace(); + public static final RecipeGroup> WORKBENCH = new RecipeGroup<>(new RecipeSymbol(new ItemStack(Block.workbench))); + static { Toml configToml = new Toml("Computers configuration file."); configToml.addCategory("BlockIDs"); @@ -112,13 +121,8 @@ public void onInitialize() { ItemToolPickaxe.miningLevels.put(computer,1); ItemToolPickaxe.miningLevels.put(diskDrive,1); - CraftingManager.getInstance().addRecipe(new ItemStack(computer, 1), "XXX", "XYX", "XZX", 'X', Block.stone, 'Y', Item.dustRedstone, 'Z', Block.glass); - CraftingManager.getInstance().addRecipe(new ItemStack(diskDrive, 1), "XXX", "XYX", "XYX", 'X', Block.stone, 'Y', Item.dustRedstone); - CraftingManager.getInstance().addRecipe(new ItemStack(disk, 1), "X", "Y", 'X', Item.dustRedstone, 'Y', Item.paper); - - - EntityHelper.createTileEntity(TileEntityComputer.class,"Computer"); - EntityHelper.createTileEntity(TileEntityDiskDrive.class,"Disk Drive"); + EntityHelper.Core.createTileEntity(TileEntityComputer.class,"Computer"); + EntityHelper.Core.createTileEntity(TileEntityDiskDrive.class,"Disk Drive"); } public static boolean isMultiplayerClient() { @@ -192,4 +196,11 @@ public static void openDiskDriveGUI(EntityPlayer entityplayer, TileEntityDiskDri public static boolean getCursorBlink() { return (m_tickCount / 6 % 2 == 0); } + + @Override + public void onRecipesReady() { + COMPUTERS.register("workbench",WORKBENCH); + Registries.RECIPES.register("computers",COMPUTERS); + DataLoader.loadRecipes("/assets/computers/workbench.json"); + } } diff --git a/src/main/java/sunsetsatellite/computers/mixin/MinecraftMixin.java b/src/main/java/sunsetsatellite/computers/mixin/MinecraftMixin.java index e5c4e69..002284c 100644 --- a/src/main/java/sunsetsatellite/computers/mixin/MinecraftMixin.java +++ b/src/main/java/sunsetsatellite/computers/mixin/MinecraftMixin.java @@ -8,7 +8,6 @@ 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; import sunsetsatellite.computers.Computers; @Mixin(value = Minecraft.class, remap = false) @@ -32,13 +31,4 @@ public void tick(CallbackInfo ci){ ItemDisk.loadLabelsIfWorldChanged(theWorld); Computers.m_tickCount++; } - - @Shadow - private static Minecraft theMinecraft; - - @Inject(method = "getMinecraft(Ljava/lang/Class;)Lnet/minecraft/client/Minecraft;", at = @At("HEAD"), cancellable = true) - private static void returnMinecraft(Class caller, CallbackInfoReturnable cir){ - cir.setReturnValue(theMinecraft); - } - } diff --git a/src/main/resources/assets/computers/workbench.json b/src/main/resources/assets/computers/workbench.json new file mode 100644 index 0000000..145da87 --- /dev/null +++ b/src/main/resources/assets/computers/workbench.json @@ -0,0 +1,100 @@ +[ + { + "name": "computers:workbench/computer", + "type": "minecraft:crafting/shaped", + "pattern": [ + "XXX", + "XYX", + "XZX" + ], + "symbols": [ + { + "symbol": "X", + "group": "minecraft:stones" + }, + { + "symbol": "Y", + "stack": { + "key": "item.dust.redstone", + "amount": 1, + "meta": 0 + } + }, + { + "symbol": "Z", + "stack": { + "key": "tile.glass", + "amount": 1, + "meta": 0 + } + } + ], + "result": { + "key": "tile.computers.computer", + "amount": 1, + "meta": 0 + }, + "consumeContainers": false + }, + { + "name": "computers:workbench/disk_drive", + "type": "minecraft:crafting/shaped", + "pattern": [ + "XXX", + "XYX", + "XYX" + ], + "symbols": [ + { + "symbol": "X", + "group": "minecraft:stones" + }, + { + "symbol": "Y", + "stack": { + "key": "item.dust.redstone", + "amount": 1, + "meta": 0 + } + } + ], + "result": { + "key": "tile.computers.diskDrive", + "amount": 1, + "meta": 0 + }, + "consumeContainers": false + }, + { + "name": "computers:workbench/disk", + "type": "minecraft:crafting/shaped", + "pattern": [ + "X", + "Y" + ], + "symbols": [ + { + "symbol": "X", + "stack": { + "key": "item.paper", + "amount": 1, + "meta": 0 + } + }, + { + "symbol": "Y", + "stack": { + "key": "item.dust.redstone", + "amount": 1, + "meta": 0 + } + } + ], + "result": { + "key": "item.computers.computerDisk", + "amount": 1, + "meta": 0 + }, + "consumeContainers": false + } +] diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0e7b589..517b9e3 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,6 +19,9 @@ "entrypoints": { "main": [ "sunsetsatellite.computers.Computers" + ], + "recipesReady": [ + "sunsetsatellite.computers.Computers" ] }, "mixins": [ @@ -26,8 +29,8 @@ ], "depends": { "fabricloader": ">=0.13.3", - "halplibe": ">=2.8.0", - "sunsetutils": ">=1.9.1" + "halplibe": ">=3.1.2", + "catalyst-core": ">=1.1.1" }, "suggests": { }