From 67d5693d2a7930683fc23ac2e41b685dddf8cde0 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Fri, 16 Nov 2018 12:29:29 +0000 Subject: [PATCH] Fix tile entities being registered with incorrect names We'd somehow added spaces, which means they weren't registered under the computercraft domain (rather, the "computercraft " one). We also create a datafixer to ensure old worlds are handled correctly. --- .../dan200/computercraft/ComputerCraft.java | 9 ++--- .../computercraft/shared/datafix/Fixes.java | 23 +++++++++++ .../shared/datafix/TileEntityDataFixer.java | 39 +++++++++++++++++++ .../shared/proxy/CCTurtleProxyCommon.java | 6 +-- .../proxy/ComputerCraftProxyCommon.java | 23 ++++++----- 5 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 src/main/java/dan200/computercraft/shared/datafix/Fixes.java create mode 100644 src/main/java/dan200/computercraft/shared/datafix/TileEntityDataFixer.java diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index 77c344db0..5d10d6e92 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -29,8 +29,6 @@ import dan200.computercraft.core.filesystem.FileMount; import dan200.computercraft.core.filesystem.FileSystemMount; import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.tracking.Tracking; -import dan200.computercraft.shared.command.CommandComputer; -import dan200.computercraft.shared.command.CommandComputerCraft; import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; import dan200.computercraft.shared.computer.blocks.BlockCommandComputer; import dan200.computercraft.shared.computer.blocks.BlockComputer; @@ -60,7 +58,10 @@ import dan200.computercraft.shared.proxy.IComputerCraftProxy; import dan200.computercraft.shared.turtle.blocks.BlockTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.upgrades.*; -import dan200.computercraft.shared.util.*; +import dan200.computercraft.shared.util.CreativeTabMain; +import dan200.computercraft.shared.util.IDAssigner; +import dan200.computercraft.shared.util.InventoryUtil; +import dan200.computercraft.shared.util.WorldUtil; import dan200.computercraft.shared.wired.CapabilityWiredElement; import dan200.computercraft.shared.wired.WiredNode; import io.netty.buffer.Unpooled; @@ -99,7 +100,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.FileSystem; import java.nio.file.FileSystems; -import java.nio.file.ProviderNotFoundException; import java.util.*; import java.util.function.Function; import java.util.zip.ZipEntry; @@ -116,7 +116,6 @@ import java.util.zip.ZipFile; public class ComputerCraft { public static final String MOD_ID = "computercraft"; - public static final String LOWER_ID = "computercraft"; // GUI IDs public static final int diskDriveGUIID = 100; diff --git a/src/main/java/dan200/computercraft/shared/datafix/Fixes.java b/src/main/java/dan200/computercraft/shared/datafix/Fixes.java new file mode 100644 index 000000000..5e1efcca1 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/datafix/Fixes.java @@ -0,0 +1,23 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.datafix; + +import dan200.computercraft.ComputerCraft; +import net.minecraft.util.datafix.FixTypes; +import net.minecraftforge.common.util.CompoundDataFixer; +import net.minecraftforge.common.util.ModFixs; + +public class Fixes +{ + public static final int VERSION = 1; + + public static void register( CompoundDataFixer fixer ) + { + ModFixs fixes = fixer.init( ComputerCraft.MOD_ID, VERSION ); + fixes.registerFix( FixTypes.BLOCK_ENTITY, new TileEntityDataFixer() ); + } +} diff --git a/src/main/java/dan200/computercraft/shared/datafix/TileEntityDataFixer.java b/src/main/java/dan200/computercraft/shared/datafix/TileEntityDataFixer.java new file mode 100644 index 000000000..dca34f9a8 --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/datafix/TileEntityDataFixer.java @@ -0,0 +1,39 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.datafix; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.datafix.IFixableData; + +import javax.annotation.Nonnull; + +import static dan200.computercraft.ComputerCraft.MOD_ID; +import static dan200.computercraft.shared.datafix.Fixes.VERSION; + +/** + * Fixes up the botched tile entity IDs from the 1.11 port. + */ +public class TileEntityDataFixer implements IFixableData +{ + @Override + public int getFixVersion() + { + return VERSION; + } + + @Nonnull + @Override + public NBTTagCompound fixTagCompound( @Nonnull NBTTagCompound tag ) + { + String id = tag.getString( "id" ); + if( id.startsWith( MOD_ID + " : " ) ) + { + tag.setString( "id", id.replaceFirst( MOD_ID + " : ", MOD_ID + ":" ) ); + } + return tag; + } +} diff --git a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java index e44e65b52..e0420b83a 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java @@ -469,9 +469,9 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy private void registerTileEntities() { // TileEntities - GameRegistry.registerTileEntity( TileTurtle.class, ComputerCraft.LOWER_ID + " : " + "turtle" ); - GameRegistry.registerTileEntity( TileTurtleExpanded.class, ComputerCraft.LOWER_ID + " : " + "turtleex" ); - GameRegistry.registerTileEntity( TileTurtleAdvanced.class, ComputerCraft.LOWER_ID + " : " + "turtleadv" ); + GameRegistry.registerTileEntity( TileTurtle.class, new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ) ); + GameRegistry.registerTileEntity( TileTurtleExpanded.class, new ResourceLocation( ComputerCraft.MOD_ID, "turtleex" ) ); + GameRegistry.registerTileEntity( TileTurtleAdvanced.class, new ResourceLocation( ComputerCraft.MOD_ID, "turtleadv" ) ); } private void registerForgeHandlers() diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 108cbb2d5..5be69e778 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -24,6 +24,7 @@ import dan200.computercraft.shared.computer.core.*; import dan200.computercraft.shared.computer.inventory.ContainerComputer; import dan200.computercraft.shared.computer.items.ItemCommandComputer; import dan200.computercraft.shared.computer.items.ItemComputer; +import dan200.computercraft.shared.datafix.Fixes; import dan200.computercraft.shared.integration.charset.IntegrationCharset; import dan200.computercraft.shared.media.common.DefaultMediaProvider; import dan200.computercraft.shared.media.inventory.ContainerHeldItem; @@ -77,6 +78,7 @@ import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.entity.player.PlayerContainerEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -121,6 +123,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy registerTileEntities(); registerForgeHandlers(); + Fixes.register( FMLCommonHandler.instance().getDataFixer() ); if( Loader.isModLoaded( ModCharset.MODID ) ) IntegrationCharset.register(); } @@ -478,16 +481,16 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy private void registerTileEntities() { // Tile Entities - GameRegistry.registerTileEntity( TileComputer.class, ComputerCraft.LOWER_ID + " : " + "computer" ); - GameRegistry.registerTileEntity( TileDiskDrive.class, ComputerCraft.LOWER_ID + " : " + "diskdrive" ); - GameRegistry.registerTileEntity( TileWirelessModem.class, ComputerCraft.LOWER_ID + " : " + "wirelessmodem" ); - GameRegistry.registerTileEntity( TileMonitor.class, ComputerCraft.LOWER_ID + " : " + "monitor" ); - GameRegistry.registerTileEntity( TilePrinter.class, ComputerCraft.LOWER_ID + " : " + "ccprinter" ); - GameRegistry.registerTileEntity( TileCable.class, ComputerCraft.LOWER_ID + " : " + "wiredmodem" ); - GameRegistry.registerTileEntity( TileCommandComputer.class, ComputerCraft.LOWER_ID + " : " + "command_computer" ); - GameRegistry.registerTileEntity( TileAdvancedModem.class, ComputerCraft.LOWER_ID + " : " + "advanced_modem" ); - GameRegistry.registerTileEntity( TileSpeaker.class, ComputerCraft.LOWER_ID + " : " + "speaker" ); - GameRegistry.registerTileEntity( TileWiredModemFull.class, ComputerCraft.LOWER_ID + " : " + "wired_modem_full" ); + GameRegistry.registerTileEntity( TileComputer.class, new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ); + GameRegistry.registerTileEntity( TileDiskDrive.class, new ResourceLocation( ComputerCraft.MOD_ID, "diskdrive" ) ); + GameRegistry.registerTileEntity( TileWirelessModem.class, new ResourceLocation( ComputerCraft.MOD_ID, "wirelessmodem" ) ); + GameRegistry.registerTileEntity( TileMonitor.class, new ResourceLocation( ComputerCraft.MOD_ID, "monitor" ) ); + GameRegistry.registerTileEntity( TilePrinter.class, new ResourceLocation( ComputerCraft.MOD_ID, "ccprinter" ) ); + GameRegistry.registerTileEntity( TileCable.class, new ResourceLocation( ComputerCraft.MOD_ID, "wiredmodem" ) ); + GameRegistry.registerTileEntity( TileCommandComputer.class, new ResourceLocation( ComputerCraft.MOD_ID, "command_computer" ) ); + GameRegistry.registerTileEntity( TileAdvancedModem.class, new ResourceLocation( ComputerCraft.MOD_ID, "advanced_modem" ) ); + GameRegistry.registerTileEntity( TileSpeaker.class, new ResourceLocation( ComputerCraft.MOD_ID, "speaker" ) ); + GameRegistry.registerTileEntity( TileWiredModemFull.class, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full" ) ); // Register peripheral providers ComputerCraftAPI.registerPeripheralProvider( new DefaultPeripheralProvider() );