From 08099f08f233008f0ea61a332d7a06ea7e9a1294 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 12 Jun 2017 09:14:57 +0100 Subject: [PATCH] Initial update to 1.12 - Convert most recipes to JSON - Add JSON factories for impostor and turtle recipes. - Several mappings changes - Migrate to Forge's new registry system --- build.gradle | 6 +- .../dan200/computercraft/ComputerCraft.java | 8 - .../client/gui/FixedWidthFontRenderer.java | 10 +- .../computercraft/client/gui/GuiConfigCC.java | 14 - .../client/gui/GuiDiskDrive.java | 4 +- .../computercraft/client/gui/GuiPrinter.java | 4 +- .../client/gui/widgets/Widget.java | 8 +- .../client/proxy/CCTurtleProxyClient.java | 11 +- .../proxy/ComputerCraftProxyClient.java | 14 +- .../render/TileEntityMonitorRenderer.java | 8 +- .../render/TileEntityTurtleRenderer.java | 13 +- .../client/render/TurtleSmartItemModel.java | 16 +- .../shared/common/BlockGeneric.java | 18 +- .../shared/common/ColourableRecipe.java | 13 +- .../shared/common/TileGeneric.java | 3 +- .../shared/computer/blocks/TileComputer.java | 3 +- .../computer/items/ItemCommandComputer.java | 12 +- .../shared/computer/items/ItemComputer.java | 3 +- .../computer/items/ItemComputerBase.java | 6 +- .../shared/media/items/ItemDiskLegacy.java | 8 +- .../shared/media/items/ItemPrintout.java | 8 +- .../shared/media/items/ItemTreasureDisk.java | 6 +- .../shared/media/recipes/DiskRecipe.java | 221 +++++----- .../shared/media/recipes/PrintoutRecipe.java | 13 +- .../shared/network/PacketHandler.java | 2 +- .../peripheral/common/ItemAdvancedModem.java | 3 +- .../shared/peripheral/common/ItemCable.java | 5 +- .../peripheral/common/ItemPeripheral.java | 3 +- .../peripheral/common/TilePeripheralBase.java | 3 +- .../shared/peripheral/modem/TileCable.java | 3 +- .../modem/WirelessModemPeripheral.java | 4 +- .../peripheral/printer/ContainerPrinter.java | 4 +- .../pocket/items/ItemPocketComputer.java | 8 +- .../recipes/PocketComputerUpgradeRecipe.java | 13 +- .../shared/proxy/CCTurtleProxyCommon.java | 201 +++++----- .../proxy/ComputerCraftProxyCommon.java | 379 +++++++----------- .../shared/proxy/ICCTurtleProxy.java | 2 - .../shared/proxy/IComputerCraftProxy.java | 2 - .../shared/turtle/blocks/TileTurtle.java | 6 +- .../shared/turtle/core/TurtleBrain.java | 12 +- .../turtle/core/TurtleCompareCommand.java | 7 +- .../turtle/core/TurtlePlaceCommand.java | 6 +- .../shared/turtle/core/TurtleSuckCommand.java | 8 +- .../turtle/entity/TurtleVisionCamera.java | 12 +- .../turtle/inventory/ContainerTurtle.java | 4 +- .../shared/turtle/items/ItemTurtleBase.java | 3 +- .../shared/turtle/recipes/TurtleRecipe.java | 91 +++-- .../turtle/recipes/TurtleUpgradeRecipe.java | 14 +- .../upgrades/TurtleInventoryCrafting.java | 4 +- .../shared/turtle/upgrades/TurtleTool.java | 4 +- .../shared/util/ImpostorRecipe.java | 39 +- .../shared/util/ImpostorShapelessRecipe.java | 40 +- .../computercraft/shared/util/RecipeUtil.java | 105 +++++ .../computercraft/shared/util/WorldUtil.java | 28 +- .../computercraft/recipes/_factories.json | 7 + .../recipes/advanced_computer.json | 14 + .../recipes/advanced_monitor.json | 13 + .../recipes/advanced_pocket_computer.json | 14 + .../recipes/advanced_turtle.json | 14 + .../assets/computercraft/recipes/cable.json | 13 + .../recipes/command_computer.json | 14 + .../computercraft/recipes/disk_drive.json | 13 + .../computercraft/recipes/disk_impostor.json | 8 + .../computercraft/recipes/ender_modem.json | 13 + .../recipes/normal_computer.json | 14 + .../computercraft/recipes/normal_monitor.json | 13 + .../recipes/normal_pocket_computer.json | 14 + .../computercraft/recipes/normal_turtle.json | 14 + .../computercraft/recipes/printed_book.json | 9 + .../computercraft/recipes/printed_pages.json | 9 + .../assets/computercraft/recipes/printer.json | 14 + .../computercraft/recipes/skull_cloudy.json | 12 + .../computercraft/recipes/skull_dan200.json | 12 + .../assets/computercraft/recipes/speaker.json | 14 + .../computercraft/recipes/wired_modem.json | 13 + .../computercraft/recipes/wireless_modem.json | 13 + 76 files changed, 1046 insertions(+), 673 deletions(-) create mode 100644 src/main/java/dan200/computercraft/shared/util/RecipeUtil.java create mode 100644 src/main/resources/assets/computercraft/recipes/_factories.json create mode 100644 src/main/resources/assets/computercraft/recipes/advanced_computer.json create mode 100644 src/main/resources/assets/computercraft/recipes/advanced_monitor.json create mode 100644 src/main/resources/assets/computercraft/recipes/advanced_pocket_computer.json create mode 100644 src/main/resources/assets/computercraft/recipes/advanced_turtle.json create mode 100644 src/main/resources/assets/computercraft/recipes/cable.json create mode 100644 src/main/resources/assets/computercraft/recipes/command_computer.json create mode 100644 src/main/resources/assets/computercraft/recipes/disk_drive.json create mode 100644 src/main/resources/assets/computercraft/recipes/disk_impostor.json create mode 100644 src/main/resources/assets/computercraft/recipes/ender_modem.json create mode 100644 src/main/resources/assets/computercraft/recipes/normal_computer.json create mode 100644 src/main/resources/assets/computercraft/recipes/normal_monitor.json create mode 100644 src/main/resources/assets/computercraft/recipes/normal_pocket_computer.json create mode 100644 src/main/resources/assets/computercraft/recipes/normal_turtle.json create mode 100644 src/main/resources/assets/computercraft/recipes/printed_book.json create mode 100644 src/main/resources/assets/computercraft/recipes/printed_pages.json create mode 100644 src/main/resources/assets/computercraft/recipes/printer.json create mode 100644 src/main/resources/assets/computercraft/recipes/skull_cloudy.json create mode 100644 src/main/resources/assets/computercraft/recipes/skull_dan200.json create mode 100644 src/main/resources/assets/computercraft/recipes/speaker.json create mode 100644 src/main/resources/assets/computercraft/recipes/wired_modem.json create mode 100644 src/main/resources/assets/computercraft/recipes/wireless_modem.json diff --git a/build.gradle b/build.gradle index 30d8d8dc1..9fd132e9d 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { } } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'org.ajoberstar:gradle-git:1.6.0' } } @@ -28,7 +28,7 @@ group = "dan200.computercraft" archivesBaseName = "ComputerCraft" minecraft { - version = "1.11.2-13.20.0.2294" + version = "1.12-14.21.1.2387" runDir = "run" replace '${version}', project.version @@ -37,7 +37,7 @@ minecraft { // stable_# stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not allways work. // simply re-run your setup task after changing the mappings to update your workspace. - mappings = "snapshot_20161227" + mappings = "snapshot_20170629" // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. } diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index 79ce077cf..0998ed225 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -396,14 +396,6 @@ public class ComputerCraft turtleProxy.init(); } - - @Mod.EventHandler - public void onMissingMappings( FMLMissingMappingsEvent event ) - { - proxy.remap( event ); - turtleProxy.remap( event ); - } - @Mod.EventHandler public void onServerStarting( FMLServerStartingEvent event ) { diff --git a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java index 4cf7fd716..cb0c7684d 100644 --- a/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java +++ b/src/main/java/dan200/computercraft/client/gui/FixedWidthFontRenderer.java @@ -8,9 +8,9 @@ package dan200.computercraft.client.gui; import dan200.computercraft.core.terminal.TextBuffer; import dan200.computercraft.shared.util.Palette; +import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; @@ -38,7 +38,7 @@ public class FixedWidthFontRenderer Arrays.fill( rgb, ( rgb[0] + rgb[1] + rgb[2] ) / 3.0f ); } - private void drawChar( VertexBuffer renderer, double x, double y, int index, int color, Palette p, boolean greyscale ) + private void drawChar( BufferBuilder renderer, double x, double y, int index, int color, Palette p, boolean greyscale ) { int column = index % 16; int row = index / 16; @@ -63,7 +63,7 @@ public class FixedWidthFontRenderer renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex(); } - private void drawQuad( VertexBuffer renderer, double x, double y, int color, double width, Palette p, boolean greyscale ) + private void drawQuad( BufferBuilder renderer, double x, double y, int color, double width, Palette p, boolean greyscale ) { double[] colour = p.getColour( 15 - color ); if(greyscale) @@ -91,7 +91,7 @@ public class FixedWidthFontRenderer { // Draw the quads Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer renderer = tessellator.getBuffer(); + BufferBuilder renderer = tessellator.getBuffer(); renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR ); if( leftMarginSize > 0.0 ) { @@ -129,7 +129,7 @@ public class FixedWidthFontRenderer { // Draw the quads Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer renderer = tessellator.getBuffer(); + BufferBuilder renderer = tessellator.getBuffer(); renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX_COLOR ); for( int i = 0; i < s.length(); i++ ) { diff --git a/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java b/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java index 5457d9eba..e3cffe555 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiConfigCC.java @@ -52,24 +52,10 @@ public class GuiConfigCC extends GuiConfig return new GuiConfigCC( parentScreen ); } - @Override - @Deprecated - public Class mainConfigGuiClass() - { - return GuiConfigCC.class; - } - @Override public Set runtimeGuiCategories() { return null; } - - @Override - @Deprecated - public RuntimeOptionGuiHandler getHandlerFor( RuntimeOptionCategoryElement runtimeOptionCategoryElement ) - { - return null; - } } } diff --git a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java index a73324d42..31761ccd3 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiDiskDrive.java @@ -30,8 +30,8 @@ public class GuiDiskDrive extends GuiContainer protected void drawGuiContainerForegroundLayer(int par1, int par2) { String title = m_diskDrive.getDisplayName().getUnformattedText(); - fontRendererObj.drawString( title, (xSize - fontRendererObj.getStringWidth(title)) / 2, 6, 0x404040 ); - fontRendererObj.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 ); + fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth(title)) / 2, 6, 0x404040 ); + fontRenderer.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 ); } @Override diff --git a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java index 7f7347448..f9702ecc5 100644 --- a/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java +++ b/src/main/java/dan200/computercraft/client/gui/GuiPrinter.java @@ -32,8 +32,8 @@ public class GuiPrinter extends GuiContainer protected void drawGuiContainerForegroundLayer(int par1, int par2) { String title = m_printer.getDisplayName().getUnformattedText(); - fontRendererObj.drawString( title, (xSize - fontRendererObj.getStringWidth(title)) / 2, 6, 0x404040 ); - fontRendererObj.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 ); + fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth(title)) / 2, 6, 0x404040 ); + fontRenderer.drawString( I18n.format("container.inventory"), 8, (ySize - 96) + 2, 0x404040 ); } @Override diff --git a/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java b/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java index 414360462..75ca19529 100644 --- a/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java +++ b/src/main/java/dan200/computercraft/client/gui/widgets/Widget.java @@ -265,7 +265,7 @@ public abstract class Widget extends Gui protected void drawTooltip( String[] lines, int x, int y ) { Minecraft mc = Minecraft.getMinecraft(); - FontRenderer fontRenderer = mc.fontRendererObj; + FontRenderer fontRenderer = mc.fontRenderer; int width = 0; for( String line : lines ) @@ -340,7 +340,7 @@ public abstract class Widget extends Gui if( renderItem != null ) { renderItem.renderItemAndEffectIntoGUI( stack, x, y ); - renderItem.renderItemOverlayIntoGUI( mc.fontRendererObj, stack, x, y, null ); + renderItem.renderItemOverlayIntoGUI( mc.fontRenderer, stack, x, y, null ); } } finally @@ -360,7 +360,7 @@ public abstract class Widget extends Gui Minecraft mc = Minecraft.getMinecraft(); try { - mc.fontRendererObj.drawString( s, x, y, color ); + mc.fontRenderer.drawString( s, x, y, color ); } finally { @@ -371,7 +371,7 @@ public abstract class Widget extends Gui protected int getStringWidth( String s ) { Minecraft mc = Minecraft.getMinecraft(); - return mc.fontRendererObj.getStringWidth( s ); + return mc.fontRenderer.getStringWidth( s ); } protected void playClickSound() diff --git a/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java index 22fdfe893..753502e4f 100644 --- a/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/CCTurtleProxyClient.java @@ -29,6 +29,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.model.IModel; import net.minecraftforge.client.model.ModelLoader; @@ -49,6 +50,13 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon { super.preInit(); + // Setup client forge handlers + registerForgeHandlers(); + } + + @SubscribeEvent + public void registerModels( ModelRegistryEvent event ) + { // Register item models ItemMeshDefinition turtleMeshDefinition = new ItemMeshDefinition() { @@ -70,9 +78,6 @@ public class CCTurtleProxyClient extends CCTurtleProxyCommon registerItemModel( ComputerCraft.Blocks.turtle, turtleMeshDefinition, turtleModelNames ); registerItemModel( ComputerCraft.Blocks.turtleExpanded, turtleMeshDefinition, turtleModelNames ); registerItemModel( ComputerCraft.Blocks.turtleAdvanced, turtleMeshDefinition, turtleModelNames ); - - // Setup client forge handlers - registerForgeHandlers(); } @Override diff --git a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java index 8ee5e9c8a..98a08dd66 100644 --- a/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java +++ b/src/main/java/dan200/computercraft/client/proxy/ComputerCraftProxyClient.java @@ -34,6 +34,7 @@ import net.minecraft.client.renderer.ItemMeshDefinition; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.color.IItemColor; +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.Item; @@ -44,6 +45,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderPlayerEvent; @@ -76,6 +78,13 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon m_tick = 0; m_renderFrame = 0; + // Setup client forge handlers + registerForgeHandlers(); + } + + @SubscribeEvent + public void registerModels( ModelRegistryEvent event ) + { // Register item models registerItemModel( ComputerCraft.Blocks.computer, new ItemMeshDefinition() { @@ -174,9 +183,6 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon "advanced_pocket_computer", "advanced_pocket_computer_on", "advanced_pocket_computer_blinking", "pocket_computer_colour", "pocket_computer_colour_on", "pocket_computer_colour_blinking", } ); - - // Setup client forge handlers - registerForgeHandlers(); } @Override @@ -304,7 +310,7 @@ public class ComputerCraftProxyClient extends ComputerCraftProxyCommon public String getRecordInfo( @Nonnull ItemStack recordStack ) { List info = new ArrayList( 1 ); - recordStack.getItem().addInformation( recordStack, null, info, false ); + recordStack.getItem().addInformation( recordStack, null, info, ITooltipFlag.TooltipFlags.NORMAL ); if( info.size() > 0 ) { return info.get( 0 ); } else { diff --git a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java index 6c009a2f6..54d3cc385 100644 --- a/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java +++ b/src/main/java/dan200/computercraft/client/render/TileEntityMonitorRenderer.java @@ -16,17 +16,15 @@ import dan200.computercraft.shared.util.Colour; import dan200.computercraft.shared.util.DirectionUtil; import dan200.computercraft.shared.util.Palette; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import org.lwjgl.opengl.GL11; -import javax.annotation.Nonnull; - public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer { public TileEntityMonitorRenderer() @@ -34,7 +32,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer quads, int[] tints ) { - VertexBuffer buffer = tessellator.getBuffer(); + BufferBuilder buffer = tessellator.getBuffer(); VertexFormat format = DefaultVertexFormats.ITEM; buffer.begin( GL11.GL_QUADS, format ); for (BakedQuad quad : quads) @@ -309,7 +308,7 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer m_cachedModels; private ItemOverrideList m_overrides; + private final TurtleModelCombination m_defaultCombination; public TurtleSmartItemModel() { - m_defaultItem = TurtleItemFactory.create( -1, null, -1, ComputerFamily.Normal, null, null, 0, null ); m_cachedModels = new HashMap(); + m_defaultCombination = new TurtleModelCombination( ComputerFamily.Normal, false, null, null, null, false ); m_overrides = new ItemOverrideList( new ArrayList() ) { @Nonnull @@ -216,6 +215,13 @@ public class TurtleSmartItemModel implements IBakedModel, IResourceManagerReload private IBakedModel getDefaultModel() { - return m_overrides.handleItemState( this, m_defaultItem, null, null ); + IBakedModel model = m_cachedModels.get( m_defaultCombination ); + if( model == null ) + { + model = buildModel( m_defaultCombination ); + m_cachedModels.put( m_defaultCombination, model ); + } + + return model; } } diff --git a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java index b7e170200..6c8240053 100644 --- a/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/BlockGeneric.java @@ -15,16 +15,18 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.EnumFacing; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.Explosion; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; @@ -46,18 +48,15 @@ public abstract class BlockGeneric extends Block implements { } - @Nonnull @Override - public final List getDrops( IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune ) + public final void getDrops( @Nonnull NonNullList drops, IBlockAccess world, BlockPos pos, @Nonnull IBlockState state, int fortune ) { - ArrayList drops = new ArrayList( 1 ); TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric ) { - TileGeneric generic = (TileGeneric)tile; + TileGeneric generic = (TileGeneric) tile; generic.getDroppedItems( drops, false ); } - return drops; } @Nonnull @@ -85,7 +84,7 @@ public abstract class BlockGeneric extends Block implements public final void dropAllItems( World world, BlockPos pos, boolean creative ) { // Get items to drop - List drops = new ArrayList( 1 ); + NonNullList drops = NonNullList.create(); TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric ) { @@ -170,6 +169,7 @@ public abstract class BlockGeneric extends Block implements } @Override + @Deprecated public final boolean isSideSolid( IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, EnumFacing side ) { TileEntity tile = world.getTileEntity( pos ); @@ -188,7 +188,7 @@ public abstract class BlockGeneric extends Block implements } @Override - public float getExplosionResistance( World world, BlockPos pos, @Nonnull Entity exploder, Explosion explosion ) + public float getExplosionResistance( World world, BlockPos pos, @Nullable Entity exploder, Explosion explosion ) { TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileGeneric && tile.hasWorld() ) @@ -199,7 +199,7 @@ public abstract class BlockGeneric extends Block implements return 2000.0f; } } - return super.getExplosionResistance( exploder ); + return super.getExplosionResistance( world, pos, exploder, explosion ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java index a7f4a1805..d86e1113c 100644 --- a/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java +++ b/src/main/java/dan200/computercraft/shared/common/ColourableRecipe.java @@ -9,10 +9,11 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.NonNullList; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.registries.IForgeRegistryEntry; import javax.annotation.Nonnull; -public class ColourableRecipe implements IRecipe +public class ColourableRecipe extends IForgeRegistryEntry.Impl implements IRecipe { @Override public boolean matches( @Nonnull InventoryCrafting inv, @Nonnull World worldIn ) @@ -79,9 +80,15 @@ public class ColourableRecipe implements IRecipe } @Override - public int getRecipeSize() + public boolean canFit( int x, int y ) { - return 2; + return x >= 2 && y >= 2; + } + + @Override + public boolean isHidden() + { + return true; } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java index 970f85f3c..943f304a9 100644 --- a/src/main/java/dan200/computercraft/shared/common/TileGeneric.java +++ b/src/main/java/dan200/computercraft/shared/common/TileGeneric.java @@ -17,6 +17,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.EnumFacing; @@ -79,7 +80,7 @@ public abstract class TileGeneric extends TileEntity getWorld().setBlockState( getPos(), newState, 3 ); } - public void getDroppedItems( @Nonnull List drops, boolean creative ) + public void getDroppedItems( @Nonnull NonNullList drops, boolean creative ) { } diff --git a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java index e37f7bd08..180129a51 100644 --- a/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/blocks/TileComputer.java @@ -16,6 +16,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; import javax.annotation.Nonnull; import java.util.List; @@ -48,7 +49,7 @@ public class TileComputer extends TileComputerBase } @Override - public void getDroppedItems( @Nonnull List drops, boolean creative ) + public void getDroppedItems( @Nonnull NonNullList drops, boolean creative ) { IComputer computer = getComputer(); if( !creative || (computer != null && computer.getLabel() != null) ) diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java index 72066a2eb..ce1c355f1 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemCommandComputer.java @@ -40,9 +40,12 @@ public class ItemCommandComputer extends ItemComputer // Build the stack ItemStack result = new ItemStack( this, 1, 0 ); - NBTTagCompound nbt = new NBTTagCompound(); - nbt.setInteger( "computerID", id ); - result.setTagCompound( nbt ); + if( id >= 0 ) + { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger( "computerID", id ); + result.setTagCompound( nbt ); + } if( label != null ) { @@ -53,8 +56,9 @@ public class ItemCommandComputer extends ItemComputer } @Override - public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) + public void getSubItems( @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Command ) ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java index cf8cdbca3..4ab2bb05d 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputer.java @@ -73,8 +73,9 @@ public class ItemComputer extends ItemComputerBase } @Override - public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) + public void getSubItems( @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Normal ) ); list.add( ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ) ); } diff --git a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java index b92e99d65..eebae25ae 100644 --- a/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java +++ b/src/main/java/dan200/computercraft/shared/computer/items/ItemComputerBase.java @@ -11,6 +11,7 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.computer.core.ComputerFamily; import net.minecraft.block.Block; +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; @@ -18,6 +19,7 @@ import net.minecraft.util.SoundEvent; import net.minecraft.world.World; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.List; public abstract class ItemComputerBase extends ItemBlock implements IComputerItem, IMedia @@ -36,9 +38,9 @@ public abstract class ItemComputerBase extends ItemBlock implements IComputerIte } @Override - public void addInformation( @Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull List list, boolean debug ) + public void addInformation( @Nonnull ItemStack stack, @Nullable World world, @Nonnull List list, @Nonnull ITooltipFlag flag ) { - if( debug ) + if( flag.isAdvanced() ) { int id = getComputerID( stack ); if( id >= 0 ) diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java index f312326c2..3efadf957 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemDiskLegacy.java @@ -12,6 +12,7 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.shared.common.IColouredItem; import dan200.computercraft.shared.util.Colour; +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -37,8 +38,9 @@ public class ItemDiskLegacy extends Item } @Override - public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList list ) + public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; for( int colour=0; colour<16; ++colour ) { ItemStack stack = createFromIDAndColour( -1, null, Colour.values()[ colour ].getHex() ); @@ -83,9 +85,9 @@ public class ItemDiskLegacy extends Item } @Override - public void addInformation( @Nonnull ItemStack stack, EntityPlayer player, List list, boolean debug ) + public void addInformation( @Nonnull ItemStack stack, World world, List list, ITooltipFlag flag ) { - if( debug ) + if( flag.isAdvanced() ) { int id = getDiskID( stack ); if( id >= 0 ) diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java index 6c133eb40..d07e57889 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemPrintout.java @@ -7,6 +7,7 @@ package dan200.computercraft.shared.media.items; import dan200.computercraft.ComputerCraft; +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -43,15 +44,16 @@ public class ItemPrintout extends Item } @Override - public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList list ) + public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; list.add( createSingleFromTitleAndText( null, new String[ LINES_PER_PAGE ], new String[ LINES_PER_PAGE ] ) ); list.add( createMultipleFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) ); list.add( createBookFromTitleAndText( null, new String[ 2*LINES_PER_PAGE ], new String[ 2*LINES_PER_PAGE ] ) ); } @Override - public void addInformation( @Nonnull ItemStack itemstack, EntityPlayer par2EntityPlayer, List list, boolean flag ) + public void addInformation( @Nonnull ItemStack itemstack, World world, List list, ITooltipFlag flag ) { String title = getTitle( itemstack ); if( title != null && title.length() > 0 ) @@ -91,7 +93,7 @@ public class ItemPrintout extends Item { ComputerCraft.openPrintoutGUI( player, hand ); } - return new ActionResult( EnumActionResult.SUCCESS, player.getHeldItem( hand ) ); + return new ActionResult<>( EnumActionResult.SUCCESS, player.getHeldItem( hand ) ); } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java index f1d667e9b..3bf3fddcd 100644 --- a/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java +++ b/src/main/java/dan200/computercraft/shared/media/items/ItemTreasureDisk.java @@ -11,6 +11,7 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.media.IMedia; import dan200.computercraft.core.filesystem.SubMount; import dan200.computercraft.shared.util.Colour; +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -23,6 +24,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; import java.util.List; @@ -37,12 +39,12 @@ public class ItemTreasureDisk extends Item } @Override - public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList list ) + public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList list ) { } @Override - public void addInformation( @Nonnull ItemStack stack, EntityPlayer player, List list, boolean bool ) + public void addInformation( @Nonnull ItemStack stack, World world, List list, ITooltipFlag flag ) { String label = getTitle( stack ); if( label != null && label.length() > 0 ) diff --git a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java index 753955e0f..c7d4459de 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/DiskRecipe.java @@ -1,107 +1,114 @@ -/* - * This file is part of ComputerCraft - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission. - * Send enquiries to dratcliffe@gmail.com - */ - -package dan200.computercraft.shared.media.recipes; - -import dan200.computercraft.shared.media.items.ItemDiskLegacy; -import dan200.computercraft.shared.util.Colour; -import dan200.computercraft.shared.util.ColourTracker; -import dan200.computercraft.shared.util.ColourUtils; -import net.minecraft.init.Items; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeHooks; - -import javax.annotation.Nonnull; - -public class DiskRecipe implements IRecipe -{ - @Override - public boolean matches( @Nonnull InventoryCrafting inv, @Nonnull World world ) - { - boolean paperFound = false; - boolean redstoneFound = false; - - for( int i = 0; i < inv.getSizeInventory(); ++i ) - { - ItemStack stack = inv.getStackInSlot( i ); - - if( !stack.isEmpty() ) - { - if( stack.getItem() == Items.PAPER ) - { - if( paperFound ) return false; - paperFound = true; - } - else if( stack.getItem() == Items.REDSTONE ) - { - if( redstoneFound ) return false; - redstoneFound = true; - } - else if( ColourUtils.getStackColour( stack ) < 0 ) - { - return false; - } - } - } - - return redstoneFound && paperFound; - } - - @Nonnull - @Override - public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv ) - { - ColourTracker tracker = new ColourTracker(); - - for( int i = 0; i < inv.getSizeInventory(); ++i ) - { - ItemStack stack = inv.getStackInSlot( i ); - - if( stack.isEmpty() ) continue; - - if( stack.getItem() != Items.PAPER && stack.getItem() != Items.REDSTONE ) - { - int index = ColourUtils.getStackColour( stack ); - if( index < 0 ) continue; - - Colour colour = Colour.values()[ index ]; - tracker.addColour( colour.getR(), colour.getG(), colour.getB() ); - } - } - - return ItemDiskLegacy.createFromIDAndColour( -1, null, tracker.hasColour() ? tracker.getColour() : Colour.Blue.getHex() ); - } - - @Override - public int getRecipeSize() - { - return 2; - } - - @Nonnull - @Override - public ItemStack getRecipeOutput() - { - return ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() ); - } - - @Nonnull - @Override - public NonNullList getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) - { - NonNullList results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); - for( int i = 0; i < results.size(); ++i ) - { - ItemStack stack = inventoryCrafting.getStackInSlot( i ); - results.set( i, ForgeHooks.getContainerItem( stack ) ); - } - return results; - } -} +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.media.recipes; + +import dan200.computercraft.shared.media.items.ItemDiskLegacy; +import dan200.computercraft.shared.util.Colour; +import dan200.computercraft.shared.util.ColourTracker; +import dan200.computercraft.shared.util.ColourUtils; +import net.minecraft.init.Items; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.util.NonNullList; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.registries.IForgeRegistryEntry; + +import javax.annotation.Nonnull; + +public class DiskRecipe extends IForgeRegistryEntry.Impl implements IRecipe +{ + @Override + public boolean matches( @Nonnull InventoryCrafting inv, @Nonnull World world ) + { + boolean paperFound = false; + boolean redstoneFound = false; + + for( int i = 0; i < inv.getSizeInventory(); ++i ) + { + ItemStack stack = inv.getStackInSlot( i ); + + if( !stack.isEmpty() ) + { + if( stack.getItem() == Items.PAPER ) + { + if( paperFound ) return false; + paperFound = true; + } + else if( stack.getItem() == Items.REDSTONE ) + { + if( redstoneFound ) return false; + redstoneFound = true; + } + else if( ColourUtils.getStackColour( stack ) < 0 ) + { + return false; + } + } + } + + return redstoneFound && paperFound; + } + + @Nonnull + @Override + public ItemStack getCraftingResult( @Nonnull InventoryCrafting inv ) + { + ColourTracker tracker = new ColourTracker(); + + for( int i = 0; i < inv.getSizeInventory(); ++i ) + { + ItemStack stack = inv.getStackInSlot( i ); + + if( stack.isEmpty() ) continue; + + if( stack.getItem() != Items.PAPER && stack.getItem() != Items.REDSTONE ) + { + int index = ColourUtils.getStackColour( stack ); + if( index < 0 ) continue; + + Colour colour = Colour.values()[ index ]; + tracker.addColour( colour.getR(), colour.getG(), colour.getB() ); + } + } + + return ItemDiskLegacy.createFromIDAndColour( -1, null, tracker.hasColour() ? tracker.getColour() : Colour.Blue.getHex() ); + } + + @Override + public boolean canFit( int x, int y ) + { + return x >= 2 && y >= 2; + } + + @Override + public boolean isHidden() + { + return true; + } + + @Nonnull + @Override + public ItemStack getRecipeOutput() + { + return ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() ); + } + + @Nonnull + @Override + public NonNullList getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) + { + NonNullList results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); + for( int i = 0; i < results.size(); ++i ) + { + ItemStack stack = inventoryCrafting.getStackInSlot( i ); + results.set( i, ForgeHooks.getContainerItem( stack ) ); + } + return results; + } +} diff --git a/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java b/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java index de4115c52..3f1b38f59 100644 --- a/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java +++ b/src/main/java/dan200/computercraft/shared/media/recipes/PrintoutRecipe.java @@ -15,19 +15,26 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.NonNullList; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.registries.IForgeRegistryEntry; import javax.annotation.Nonnull; -public class PrintoutRecipe implements IRecipe +public class PrintoutRecipe extends IForgeRegistryEntry.Impl implements IRecipe { public PrintoutRecipe( ) { } @Override - public int getRecipeSize() + public boolean canFit( int x, int y ) { - return 3; + return x >= 3 && y >= 3; + } + + @Override + public boolean isHidden() + { + return true; } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/network/PacketHandler.java b/src/main/java/dan200/computercraft/shared/network/PacketHandler.java index 64c669794..4e11b9df2 100644 --- a/src/main/java/dan200/computercraft/shared/network/PacketHandler.java +++ b/src/main/java/dan200/computercraft/shared/network/PacketHandler.java @@ -35,7 +35,7 @@ public class PacketHandler { ComputerCraftPacket packet = new ComputerCraftPacket(); packet.fromBytes( event.getPacket().payload() ); - ComputerCraft.handlePacket( packet, ((NetHandlerPlayServer)event.getHandler()).playerEntity ); + ComputerCraft.handlePacket( packet, ((NetHandlerPlayServer)event.getHandler()).player ); } catch( Exception e ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java index 9320d8064..2de3b27b9 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemAdvancedModem.java @@ -51,8 +51,9 @@ public class ItemAdvancedModem extends ItemPeripheralBase } @Override - public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) + public void getSubItems( @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; list.add( PeripheralItemFactory.create( PeripheralType.AdvancedModem, null, 1 ) ); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java index 09952bba4..6f2e76c9f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java @@ -62,8 +62,9 @@ public class ItemCable extends ItemPeripheralBase } @Override - public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) + public void getSubItems( @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; list.add( PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.Cable, null, 1 ) ); } @@ -108,7 +109,7 @@ public class ItemCable extends ItemPeripheralBase } // Try to add on the side of something - if( !existing.isAir( existingState, world, pos ) && (type == PeripheralType.Cable || existing.isSideSolid( existingState, world, pos, side )) ) + if( !existing.isAir( existingState, world, pos ) && (type == PeripheralType.Cable || existingState.isSideSolid( world, pos, side )) ) { BlockPos offset = pos.offset( side ); Block offsetExisting = world.getBlockState( offset ).getBlock(); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java index 4a7f422fb..d17ffa545 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemPeripheral.java @@ -77,8 +77,9 @@ public class ItemPeripheral extends ItemPeripheralBase } @Override - public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) + public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; list.add( PeripheralItemFactory.create( PeripheralType.DiskDrive, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.Printer, null, 1 ) ); list.add( PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ) ); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java b/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java index edd38a31c..6adb0fee3 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/TilePeripheralBase.java @@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ITickable; import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; import javax.annotation.Nonnull; import java.util.List; @@ -46,7 +47,7 @@ public abstract class TilePeripheralBase extends TileGeneric } @Override - public void getDroppedItems( @Nonnull List drops, boolean creative ) + public void getDroppedItems( @Nonnull NonNullList drops, boolean creative ) { if( !creative ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java index 7e563a077..9e22b1e3f 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java @@ -30,6 +30,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -298,7 +299,7 @@ public class TileCable extends TileModemBase } @Override - public void getDroppedItems( @Nonnull List drops, boolean creative ) + public void getDroppedItems( @Nonnull NonNullList drops, boolean creative ) { if( !creative ) { diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java index 27ad9701d..627eafc2a 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/WirelessModemPeripheral.java @@ -46,9 +46,9 @@ public abstract class WirelessModemPeripheral extends ModemPeripheral minRange = (double) ComputerCraft.modem_rangeDuringStorm; maxRange = (double) ComputerCraft.modem_highAltitudeRangeDuringStorm; } - if( position.yCoord > 96.0 && maxRange > minRange ) + if( position.y > 96.0 && maxRange > minRange ) { - return minRange + ( position.yCoord - 96.0 ) * ( ( maxRange - minRange ) / ( ( world.getHeight() - 1 ) - 96.0 ) ); + return minRange + ( position.y - 96.0 ) * ( ( maxRange - minRange ) / ( ( world.getHeight() - 1 ) - 96.0 ) ); } return minRange; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java index 9a9508bd1..b333a76d6 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/printer/ContainerPrinter.java @@ -66,7 +66,7 @@ public class ContainerPrinter extends Container public void addListener( IContainerListener crafting ) { super.addListener( crafting ); - crafting.sendProgressBarUpdate( this, 0, m_printer.isPrinting() ? 1 : 0 ); + crafting.sendWindowProperty( this, 0, m_printer.isPrinting() ? 1 : 0 ); } @Override @@ -81,7 +81,7 @@ public class ContainerPrinter extends Container { if( printing != m_lastPrinting ) { - listener.sendProgressBarUpdate( this, 0, printing ? 1 : 0 ); + listener.sendWindowProperty( this, 0, printing ? 1 : 0 ); } } m_lastPrinting = printing; diff --git a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java index 6ca6ce02e..1e7efb71b 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java +++ b/src/main/java/dan200/computercraft/shared/pocket/items/ItemPocketComputer.java @@ -20,6 +20,7 @@ import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.pocket.apis.PocketAPI; import dan200.computercraft.shared.pocket.core.PocketServerComputer; import dan200.computercraft.shared.util.StringUtil; +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -86,8 +87,9 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I } @Override - public void getSubItems( @Nonnull Item itemID, CreativeTabs tabs, NonNullList list ) + public void getSubItems( @Nonnull CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; getSubItems( list, ComputerFamily.Normal ); getSubItems( list, ComputerFamily.Advanced ); } @@ -223,9 +225,9 @@ public class ItemPocketComputer extends Item implements IComputerItem, IMedia, I } @Override - public void addInformation( @Nonnull ItemStack stack, EntityPlayer player, List list, boolean debug ) + public void addInformation( @Nonnull ItemStack stack, World world, List list, ITooltipFlag flag ) { - if( debug ) + if( flag.isAdvanced() ) { int id = getComputerID( stack ); if( id >= 0 ) diff --git a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java index fefd7dd7a..4497f19db 100644 --- a/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/pocket/recipes/PocketComputerUpgradeRecipe.java @@ -17,19 +17,26 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.NonNullList; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.registries.IForgeRegistryEntry; import javax.annotation.Nonnull; -public class PocketComputerUpgradeRecipe implements IRecipe +public class PocketComputerUpgradeRecipe extends IForgeRegistryEntry.Impl implements IRecipe { public PocketComputerUpgradeRecipe() { } @Override - public int getRecipeSize() + public boolean canFit( int x, int y ) { - return 2; + return x >= 2 && y >= 2; + } + + @Override + public boolean isHidden() + { + return true; } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java index 75fed69d9..2b4474ed0 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/CCTurtleProxyCommon.java @@ -8,10 +8,7 @@ package dan200.computercraft.shared.proxy; import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.turtle.ITurtleUpgrade; -import dan200.computercraft.core.computer.Computer; import dan200.computercraft.shared.computer.core.ComputerFamily; -import dan200.computercraft.shared.computer.items.ComputerItemFactory; -import dan200.computercraft.shared.peripheral.speaker.SpeakerPeripheral; import dan200.computercraft.shared.turtle.blocks.BlockTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtle; import dan200.computercraft.shared.turtle.blocks.TileTurtleAdvanced; @@ -21,7 +18,6 @@ import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced; import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy; import dan200.computercraft.shared.turtle.items.ItemTurtleNormal; import dan200.computercraft.shared.turtle.items.TurtleItemFactory; -import dan200.computercraft.shared.turtle.recipes.TurtleRecipe; import dan200.computercraft.shared.turtle.recipes.TurtleUpgradeRecipe; import dan200.computercraft.shared.turtle.upgrades.*; import dan200.computercraft.shared.util.IEntityDropConsumer; @@ -30,22 +26,19 @@ import dan200.computercraft.shared.util.InventoryUtil; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; -import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent; -import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.registry.EntityRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; -import net.minecraftforge.oredict.RecipeSorter; +import net.minecraftforge.registries.IForgeRegistry; import javax.annotation.Nonnull; import java.util.*; @@ -68,11 +61,18 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy @Override public void preInit() { + MinecraftForge.EVENT_BUS.register( this ); + EntityRegistry.registerModEntity( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_player" ), TurtlePlayer.class, "turtle_player", 0, ComputerCraft.instance, Integer.MAX_VALUE, Integer.MAX_VALUE, false ); - registerItems(); + + registerUpgrades(); + + // Recipe types + // RecipeSorter.register( "computercraft:turtle", TurtleRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); + // RecipeSorter.register( "computercraft:turtle_upgrade", TurtleUpgradeRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); } @Override @@ -264,12 +264,48 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy m_legacyTurtleUpgrades.put( legacyID, upgrade ); } m_turtleUpgrades.put( id, upgrade ); + } + + @SubscribeEvent + public void registerBlocks( RegistryEvent.Register event ) + { + IForgeRegistry registry = event.getRegistry(); + + // Turtle + ComputerCraft.Blocks.turtle = BlockTurtle.createTurtleBlock(); + registry.register( ComputerCraft.Blocks.turtle.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ) ) ); + + ComputerCraft.Blocks.turtleExpanded = BlockTurtle.createTurtleBlock(); + registry.register( ComputerCraft.Blocks.turtleExpanded.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_expanded" ) ) ); + + // Advanced Turtle + ComputerCraft.Blocks.turtleAdvanced = BlockTurtle.createTurtleBlock(); + registry.register( ComputerCraft.Blocks.turtleAdvanced.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ) ) ); + } + + @SubscribeEvent + public void registerItems( RegistryEvent.Register event ) + { + IForgeRegistry registry = event.getRegistry(); + + registry.register( new ItemTurtleLegacy( ComputerCraft.Blocks.turtle).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ) ) ); + registry.register( new ItemTurtleNormal( ComputerCraft.Blocks.turtleExpanded ).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_expanded" ) ) ); + registry.register( new ItemTurtleAdvanced( ComputerCraft.Blocks.turtleAdvanced ).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ) ) ); + } + + @SubscribeEvent + public void registerRecipes( RegistryEvent.Register event ) + { + IForgeRegistry registry = event.getRegistry(); + registry.register( new TurtleUpgradeRecipe().setRegistryName( new ResourceLocation( "computercraft:turtle" ) ) ); // Add a bunch of impostor recipes - if( isUpgradeVanilla( upgrade ) ) + // TODO: Figure out a way to do this in a "nice" way. + for( ITurtleUpgrade upgrade : m_turtleUpgrades.values() ) { + if( !isUpgradeVanilla( upgrade ) ) continue; + // Add fake recipes to fool NEI - List recipeList = CraftingManager.getInstance().getRecipeList(); ItemStack craftingItem = upgrade.getCraftingItem(); // A turtle just containing this upgrade @@ -285,22 +321,29 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy { ItemStack craftedTurtle = TurtleItemFactory.create( -1, null, -1, family, upgrade, null, 0, null ); ItemStack craftedTurtleFlipped = TurtleItemFactory.create( -1, null, -1, family, null, upgrade, 0, null ); - recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { baseTurtle, craftingItem }, craftedTurtle ) ); - recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { craftingItem, baseTurtle }, craftedTurtleFlipped ) ); + registry.register( + new ImpostorRecipe( "computercraft:" + family.toString() + "_turtle_upgrade", 2, 1, new ItemStack[] { baseTurtle, craftingItem }, craftedTurtle ) + .setRegistryName( new ResourceLocation( "computercraft:" + family + "_turtle_upgrade_" + upgrade.getUpgradeID().toString().replace( ':', '_' ) + "_1" ) ) + ); + registry.register( + new ImpostorRecipe( "computercraft:" + family.toString() + "_turtle_upgrade", 2, 1, new ItemStack[] { craftingItem, baseTurtle }, craftedTurtleFlipped ) + .setRegistryName( new ResourceLocation( "computercraft:" + family + "_turtle_upgrade_" + upgrade.getUpgradeID().toString().replace( ':', '_' ) + "_2" ) ) + ); + /* // A turtle containing this upgrade and another upgrade for( ITurtleUpgrade otherUpgrade : m_turtleUpgrades.values() ) { if( isUpgradeVanilla( otherUpgrade ) && isUpgradeSuitableForFamily( family, otherUpgrade ) ) { ItemStack otherCraftingItem = otherUpgrade.getCraftingItem(); - + ItemStack otherCraftedTurtle = TurtleItemFactory.create( -1, null, -1, family, null, otherUpgrade, 0, null ); ItemStack comboCraftedTurtle = TurtleItemFactory.create( -1, null, -1, family, upgrade, otherUpgrade, 0, null ); - + ItemStack otherCraftedTurtleFlipped = TurtleItemFactory.create( -1, null, -1, family, otherUpgrade, null, 0, null ); ItemStack comboCraftedTurtleFlipped = TurtleItemFactory.create( -1, null, -1, family, otherUpgrade, upgrade, 0, null ); - + recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { otherCraftingItem, craftedTurtle }, comboCraftedTurtle ) ); recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { otherCraftedTurtle, craftingItem }, comboCraftedTurtle ) ); recipeList.add( new ImpostorRecipe( 2, 1, new ItemStack[] { craftedTurtleFlipped, otherCraftingItem }, comboCraftedTurtleFlipped ) ); @@ -309,67 +352,14 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy recipeList.add( new ImpostorRecipe( 3, 1, new ItemStack[] { craftingItem, baseTurtle, otherCraftingItem }, comboCraftedTurtleFlipped ) ); } } + */ } } } } - - private void registerItems() + + private void registerUpgrades() { - // Blocks - // Turtle - ComputerCraft.Blocks.turtle = BlockTurtle.createTurtleBlock(); - registerBlock( ComputerCraft.Blocks.turtle, new ItemTurtleLegacy(ComputerCraft.Blocks.turtle), "turtle" ); - - ComputerCraft.Blocks.turtleExpanded = BlockTurtle.createTurtleBlock(); - registerBlock( ComputerCraft.Blocks.turtleExpanded, new ItemTurtleNormal( ComputerCraft.Blocks.turtleExpanded ), "turtle_expanded" ); - - // Advanced Turtle - ComputerCraft.Blocks.turtleAdvanced = BlockTurtle.createTurtleBlock(); - registerBlock( ComputerCraft.Blocks.turtleAdvanced, new ItemTurtleAdvanced( ComputerCraft.Blocks.turtleAdvanced ), "turtle_advanced" ); - - // Recipe types - RecipeSorter.register( "computercraft:turtle", TurtleRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); - RecipeSorter.register( "computercraft:turtle_upgrade", TurtleUpgradeRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); - - // Recipes - // Turtle - GameRegistry.addRecipe( new TurtleRecipe( new Item[] { - Items.IRON_INGOT, Items.IRON_INGOT, Items.IRON_INGOT, - Items.IRON_INGOT, Item.getItemFromBlock( ComputerCraft.Blocks.computer ), Items.IRON_INGOT, - Items.IRON_INGOT, Item.getItemFromBlock( Blocks.CHEST ), Items.IRON_INGOT, - }, ComputerFamily.Normal ) ); - GameRegistry.addRecipe( new TurtleUpgradeRecipe() ); - - // Impostor Turtle recipe (to fool NEI) - ItemStack iron = new ItemStack( Items.IRON_INGOT, 1 ); - GameRegistry.addRecipe( new ImpostorRecipe( 3, 3, - new ItemStack[] { - iron, iron, iron, - iron, ComputerItemFactory.create( -1, null, ComputerFamily.Normal ), iron, - iron, new ItemStack( Blocks.CHEST, 1 ), iron, - }, - TurtleItemFactory.create( -1, null, -1, ComputerFamily.Normal, null, null, 0, null ) - ) ); - - // Advanced Turtle - GameRegistry.addRecipe( new TurtleRecipe( new Item[] { - Items.GOLD_INGOT, Items.GOLD_INGOT, Items.GOLD_INGOT, - Items.GOLD_INGOT, Item.getItemFromBlock( ComputerCraft.Blocks.computer ), Items.GOLD_INGOT, - Items.GOLD_INGOT, Item.getItemFromBlock( Blocks.CHEST ), Items.GOLD_INGOT, - }, ComputerFamily.Advanced ) ); - - // Impostor Advanced Turtle recipe (to fool NEI) - ItemStack gold = new ItemStack( Items.GOLD_INGOT, 1 ); - GameRegistry.addRecipe( new ImpostorRecipe( 3, 3, - new ItemStack[] { - gold, gold, gold, - gold, ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ), gold, - gold, new ItemStack( Blocks.CHEST, 1 ), gold, - }, - TurtleItemFactory.create( -1, null, -1, ComputerFamily.Advanced, null, null, 0, null ) - ) ); - // Upgrades ComputerCraft.Upgrades.wirelessModem = new TurtleModem( false, new ResourceLocation( "computercraft", "wireless_modem" ), 1 ); registerTurtleUpgradeInternal( ComputerCraft.Upgrades.wirelessModem ); @@ -397,63 +387,64 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy ComputerCraft.Upgrades.turtleSpeaker = new TurtleSpeaker( new ResourceLocation( "computercraft", "speaker" ), 8 ); registerTurtleUpgradeInternal( ComputerCraft.Upgrades.turtleSpeaker ); - } - @Override - public void remap( FMLMissingMappingsEvent mappings ) + @SubscribeEvent + public void remapItems( RegistryEvent.MissingMappings mappings ) { - // We have to use mappings.getAll() as the mod ID is upper case but the domain lower. - for( FMLMissingMappingsEvent.MissingMapping mapping : mappings.getAll() ) + // We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower. + for( RegistryEvent.MissingMappings.Mapping mapping : mappings.getAllMappings() ) { - String domain = mapping.resourceLocation.getResourceDomain(); + String domain = mapping.key.getResourceDomain(); if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue; - String key = mapping.resourceLocation.getResourcePath(); + String key = mapping.key.getResourcePath(); if( key.equalsIgnoreCase( "CC-Turtle" ) ) { - remap( mapping, ComputerCraft.Blocks.turtle ); + mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.turtle ) ); } else if( key.equalsIgnoreCase( "CC-TurtleExpanded" ) ) { - remap( mapping, ComputerCraft.Blocks.turtleExpanded ); + mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.turtleExpanded ) ); } else if( key.equalsIgnoreCase( "CC-TurtleAdvanced" ) ) { - remap( mapping, ComputerCraft.Blocks.turtleAdvanced ); + mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.turtleAdvanced ) ); } } } - private static void remap( FMLMissingMappingsEvent.MissingMapping mapping, Block block ) + @SubscribeEvent + public void remapBlocks( RegistryEvent.MissingMappings mappings ) { - if( mapping.type == GameRegistry.Type.BLOCK ) + // We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower. + for( RegistryEvent.MissingMappings.Mapping mapping : mappings.getAllMappings() ) { - mapping.remap( block ); - } - else - { - mapping.remap( Item.getItemFromBlock( block ) ); - } - } + String domain = mapping.key.getResourceDomain(); + if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue; - private void registerBlock( Block block, Item item, String name ) - { - GameRegistry.register( block.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); - GameRegistry.register( item.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); - } - - private void registerTileEntity( Class klass, String name ) - { - GameRegistry.registerTileEntityWithAlternatives( klass, ComputerCraft.LOWER_ID + " : " + name, name ); + String key = mapping.key.getResourcePath(); + if( key.equalsIgnoreCase( "CC-Turtle" ) ) + { + mapping.remap( ComputerCraft.Blocks.turtle ); + } + else if( key.equalsIgnoreCase( "CC-TurtleExpanded" ) ) + { + mapping.remap( ComputerCraft.Blocks.turtleExpanded ); + } + else if( key.equalsIgnoreCase( "CC-TurtleAdvanced" ) ) + { + mapping.remap( ComputerCraft.Blocks.turtleAdvanced ); + } + } } private void registerTileEntities() { // TileEntities - registerTileEntity( TileTurtle.class, "turtle" ); - registerTileEntity( TileTurtleExpanded.class, "turtleex" ); - registerTileEntity( TileTurtleAdvanced.class, "turtleadv" ); + GameRegistry.registerTileEntity( TileTurtle.class, ComputerCraft.LOWER_ID + " : " + "turtle" ); + GameRegistry.registerTileEntity( TileTurtleExpanded.class, ComputerCraft.LOWER_ID + " : " + "turtleex" ); + GameRegistry.registerTileEntity( TileTurtleAdvanced.class, ComputerCraft.LOWER_ID + " : " + "turtleadv" ); } private void registerForgeHandlers() @@ -484,7 +475,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy // All checks have passed, lets dispatch the drops for(EntityItem entityItem : drops) { - consumer.consumeDrop( entity, entityItem.getEntityItem() ); + consumer.consumeDrop( entity, entityItem.getItem() ); } drops.clear(); } diff --git a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java index 7b106ca17..1d0ddc7d6 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ComputerCraftProxyCommon.java @@ -20,7 +20,6 @@ import dan200.computercraft.shared.computer.blocks.TileComputer; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.inventory.ContainerComputer; -import dan200.computercraft.shared.computer.items.ComputerItemFactory; import dan200.computercraft.shared.computer.items.ItemCommandComputer; import dan200.computercraft.shared.computer.items.ItemComputer; import dan200.computercraft.shared.media.common.DefaultMediaProvider; @@ -32,7 +31,6 @@ import dan200.computercraft.shared.media.items.ItemTreasureDisk; import dan200.computercraft.shared.media.recipes.DiskRecipe; import dan200.computercraft.shared.media.recipes.PrintoutRecipe; import dan200.computercraft.shared.network.ComputerCraftPacket; -import dan200.computercraft.shared.peripheral.PeripheralType; import dan200.computercraft.shared.peripheral.commandblock.CommandBlockPeripheralProvider; import dan200.computercraft.shared.peripheral.common.*; import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive; @@ -59,31 +57,28 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemRecord; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumHand; -import net.minecraft.util.IThreadListener; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.SoundEvent; +import net.minecraft.util.*; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.client.event.ConfigChangedEvent; -import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.common.network.FMLNetworkEvent; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; -import net.minecraftforge.oredict.RecipeSorter; +import net.minecraftforge.registries.IForgeRegistry; import javax.annotation.Nonnull; import java.io.File; @@ -99,7 +94,18 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy @Override public void preInit() { - registerItems(); + MinecraftForge.EVENT_BUS.register( this ); + + // Creative tab + ComputerCraft.mainCreativeTab = new CreativeTabMain( CreativeTabs.getNextID() ); + + // Recipe types + // RecipeSorter.register( "computercraft:impostor", ImpostorRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); + // RecipeSorter.register( "computercraft:impostor_shapeless", ImpostorShapelessRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); + // RecipeSorter.register( "computercraft:disk", DiskRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); + // RecipeSorter.register( "computercraft:colour", ColourableRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); + // RecipeSorter.register( "computercraft:printout", PrintoutRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); + // RecipeSorter.register( "computercraft:pocket_computer_upgrade", PocketComputerUpgradeRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); } @Override @@ -159,6 +165,7 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy @Override public abstract Object getPocketComputerGUI( EntityPlayer player, EnumHand hand ); + @Override public abstract File getWorldDir( World world ); @Override @@ -228,224 +235,117 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy } } - private void registerItems() + @SubscribeEvent + public void registerBlocks( RegistryEvent.Register event ) { - // Creative tab - ComputerCraft.mainCreativeTab = new CreativeTabMain( CreativeTabs.getNextID() ); + IForgeRegistry registry = event.getRegistry(); - // Blocks // Computer ComputerCraft.Blocks.computer = new BlockComputer(); - registerBlock( ComputerCraft.Blocks.computer, new ItemComputer( ComputerCraft.Blocks.computer ), "computer" ); + registry.register( ComputerCraft.Blocks.computer.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) ); // Peripheral ComputerCraft.Blocks.peripheral = new BlockPeripheral(); - registerBlock( ComputerCraft.Blocks.peripheral, new ItemPeripheral( ComputerCraft.Blocks.peripheral ), "peripheral" ); + registry.register( ComputerCraft.Blocks.peripheral.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "peripheral" ) ) ); // Cable ComputerCraft.Blocks.cable = new BlockCable(); - registerBlock( ComputerCraft.Blocks.cable, new ItemCable( ComputerCraft.Blocks.cable ), "cable" ); + registry.register( ComputerCraft.Blocks.cable.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "cable" ) ) ); // Command Computer ComputerCraft.Blocks.commandComputer = new BlockCommandComputer(); - registerBlock( ComputerCraft.Blocks.commandComputer, new ItemCommandComputer( ComputerCraft.Blocks.commandComputer ), "command_computer" ); + registry.register( ComputerCraft.Blocks.commandComputer.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "command_computer" ) ) ); // Command Computer ComputerCraft.Blocks.advancedModem = new BlockAdvancedModem(); - registerBlock( ComputerCraft.Blocks.advancedModem, new ItemAdvancedModem( ComputerCraft.Blocks.advancedModem ), "advanced_modem" ); + registry.register( ComputerCraft.Blocks.advancedModem.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "advanced_modem" ) ) ); + } + + @SubscribeEvent + public void registerItems( RegistryEvent.Register event ) + { + IForgeRegistry registry = event.getRegistry(); + + // Computer + registry.register( new ItemComputer( ComputerCraft.Blocks.computer ).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) ); + + // Peripheral + registry.register( new ItemPeripheral( ComputerCraft.Blocks.peripheral ).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "peripheral" ) ) ); + + // Cable + registry.register( new ItemCable( ComputerCraft.Blocks.cable ).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "cable" ) ) ); + + // Command Computer + registry.register( new ItemCommandComputer( ComputerCraft.Blocks.commandComputer ).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "command_computer" ) ) ); + + // Command Computer + registry.register( new ItemAdvancedModem( ComputerCraft.Blocks.advancedModem ).setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "advanced_modem" ) ) ); // Items // Floppy Disk ComputerCraft.Items.disk = new ItemDiskLegacy(); - GameRegistry.register( ComputerCraft.Items.disk.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "disk" ) ) ); + registry.register( ComputerCraft.Items.disk.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "disk" ) ) ); ComputerCraft.Items.diskExpanded = new ItemDiskExpanded(); - GameRegistry.register( ComputerCraft.Items.diskExpanded.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "disk_expanded" ) ) ); + registry.register( ComputerCraft.Items.diskExpanded.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "disk_expanded" ) ) ); // Treasure Disk ComputerCraft.Items.treasureDisk = new ItemTreasureDisk(); - GameRegistry.register( ComputerCraft.Items.treasureDisk.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "treasure_disk" ) ) ); + registry.register( ComputerCraft.Items.treasureDisk.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "treasure_disk" ) ) ); // Printout ComputerCraft.Items.printout = new ItemPrintout(); - GameRegistry.register( ComputerCraft.Items.printout.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "printout" ) ) ); + registry.register( ComputerCraft.Items.printout.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "printout" ) ) ); // Pocket computer ComputerCraft.Items.pocketComputer = new ItemPocketComputer(); - GameRegistry.register( ComputerCraft.Items.pocketComputer.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "pocket_computer" ) ) ); + registry.register( ComputerCraft.Items.pocketComputer.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, "pocket_computer" ) ) ); + } - // Recipe types - RecipeSorter.register( "computercraft:impostor", ImpostorRecipe.class, RecipeSorter.Category.SHAPED, "after:minecraft:shapeless" ); - RecipeSorter.register( "computercraft:impostor_shapeless", ImpostorShapelessRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); - RecipeSorter.register( "computercraft:disk", DiskRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); - RecipeSorter.register( "computercraft:colour", ColourableRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); - RecipeSorter.register( "computercraft:printout", PrintoutRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); - RecipeSorter.register( "computercraft:pocket_computer_upgrade", PocketComputerUpgradeRecipe.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless" ); - - // Recipes - // Computer - ItemStack computer = ComputerItemFactory.create( -1, null, ComputerFamily.Normal ); - GameRegistry.addRecipe( computer, - "XXX", "XYX", "XZX", - 'X', Blocks.STONE, - 'Y', Items.REDSTONE, - 'Z', Blocks.GLASS_PANE - ); - - // Advanced Computer - ItemStack advancedComputer = ComputerItemFactory.create( -1, null, ComputerFamily.Advanced ); - GameRegistry.addRecipe( advancedComputer, - "XXX", "XYX", "XZX", - 'X', Items.GOLD_INGOT, - 'Y', Items.REDSTONE, - 'Z', Blocks.GLASS_PANE - ); - - // Disk Drive - ItemStack diskDrive = PeripheralItemFactory.create( PeripheralType.DiskDrive, null, 1 ); - GameRegistry.addRecipe( diskDrive, - "XXX", "XYX", "XYX", - 'X', Blocks.STONE, - 'Y', Items.REDSTONE - ); - - // Speaker - ItemStack speaker = PeripheralItemFactory.create( PeripheralType.Speaker, null, 1); - GameRegistry.addRecipe( speaker, - "XXX", "XYX", "XZX", - 'X', Blocks.STONE, - 'Y', Blocks.NOTEBLOCK, - 'Z', Items.REDSTONE - ); - - // Wireless Modem - ItemStack wirelessModem = PeripheralItemFactory.create( PeripheralType.WirelessModem, null, 1 ); - GameRegistry.addRecipe( wirelessModem, - "XXX", "XYX", "XXX", - 'X', Blocks.STONE, - 'Y', Items.ENDER_PEARL - ); - - // Monitor - ItemStack monitor = PeripheralItemFactory.create( PeripheralType.Monitor, null, 1 ); - GameRegistry.addRecipe( monitor, - "XXX", "XYX", "XXX", - 'X', Blocks.STONE, - 'Y', Blocks.GLASS_PANE - ); - - // PrinterEmpty - ItemStack printer = PeripheralItemFactory.create( PeripheralType.Printer, null, 1 ); - GameRegistry.addRecipe( printer, - "XXX", "XYX", "XZX", - 'X', Blocks.STONE, - 'Y', Items.REDSTONE, - 'Z', new ItemStack( Items.DYE, 1, 0 ) // 0 = Black - ); - - // Advanced Monitor - ItemStack advancedMonitors = PeripheralItemFactory.create( PeripheralType.AdvancedMonitor, null, 4 ); - GameRegistry.addRecipe( advancedMonitors, - "XXX", "XYX", "XXX", - 'X', Items.GOLD_INGOT, - 'Y', Blocks.GLASS_PANE - ); - - // Networking Cable - ItemStack cable = PeripheralItemFactory.create( PeripheralType.Cable, null, 6 ); - GameRegistry.addRecipe( cable, - " X ", "XYX", " X ", - 'X', Blocks.STONE, - 'Y', Items.REDSTONE - ); - - // Wired Modem - ItemStack wiredModem = PeripheralItemFactory.create( PeripheralType.WiredModem, null, 1 ); - GameRegistry.addRecipe( wiredModem, - "XXX", "XYX", "XXX", - 'X', Blocks.STONE, - 'Y', Items.REDSTONE - ); - - // Computer - ItemStack commandComputer = ComputerItemFactory.create( -1, null, ComputerFamily.Command ); - GameRegistry.addRecipe( commandComputer, - "XXX", "XYX", "XZX", - 'X', Blocks.STONE, - 'Y', Blocks.COMMAND_BLOCK, - 'Z', Blocks.GLASS_PANE - ); - - // Advanced Modem - ItemStack advancedModem = PeripheralItemFactory.create( PeripheralType.AdvancedModem, null, 1 ); - GameRegistry.addRecipe( advancedModem, - "XXX", "XYX", "XXX", - 'X', Items.GOLD_INGOT, - 'Y', Items.ENDER_EYE - ); + @SubscribeEvent + public void registerRecipes( RegistryEvent.Register event ) + { + IForgeRegistry registry = event.getRegistry(); // Disk - GameRegistry.addRecipe( new DiskRecipe() ); + registry.register( new DiskRecipe().setRegistryName( new ResourceLocation( "computercraft:disk" ) ) ); // Colourable items (turtles, disks) - GameRegistry.addRecipe( new ColourableRecipe() ); + registry.register( new ColourableRecipe().setRegistryName( new ResourceLocation( "computercraft:colour" ) ) ); // Impostor Disk recipes (to fool NEI) ItemStack paper = new ItemStack( Items.PAPER, 1 ); ItemStack redstone = new ItemStack( Items.REDSTONE, 1 ); - ItemStack basicDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.Blue.getHex() ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( basicDisk, new ItemStack[]{redstone, paper} ) ); - - for (int colour = 0; colour < 16; ++colour) + for( int colour = 0; colour < 16; ++colour ) { - ItemStack disk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[colour].getHex() ); + ItemStack disk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[ colour ].getHex() ); ItemStack dye = new ItemStack( Items.DYE, 1, colour ); - for (int otherColour = 0; otherColour < 16; ++otherColour) + + int diskIdx = 0; + ItemStack[] disks = new ItemStack[ 15 ]; + for( int otherColour = 0; otherColour < 16; ++otherColour ) { - if (colour != otherColour) + if( colour != otherColour ) { - ItemStack otherDisk = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[colour].getHex() ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new ItemStack[]{ - otherDisk, dye - } ) ); + disks[ diskIdx++ ] = ItemDiskLegacy.createFromIDAndColour( -1, null, Colour.values()[ otherColour ].getHex() ); } } - GameRegistry.addRecipe( new ImpostorShapelessRecipe( disk, new ItemStack[]{ - redstone, paper, dye - } ) ); + + // Normal recipe + registry.register( + new ImpostorShapelessRecipe( "computercraft:disk", disk, new ItemStack[] { redstone, paper, dye } ) + .setRegistryName( new ResourceLocation( "computercraft:disk_imposter_" + colour ) ) + ); + + // Conversion recipe + registry.register( + new ImpostorShapelessRecipe( "computercraft:disk", disk, NonNullList.from( Ingredient.EMPTY, Ingredient.fromStacks( disks ), Ingredient.fromStacks( dye ) ) ) + .setRegistryName( new ResourceLocation( "computercraft:disk_imposter_convert_" + colour ) ) + ); } // Printout - GameRegistry.addRecipe( new PrintoutRecipe() ); - - ItemStack singlePrintout = ItemPrintout.createSingleFromTitleAndText( null, null, null ); - ItemStack multiplePrintout = ItemPrintout.createMultipleFromTitleAndText( null, null, null ); - ItemStack bookPrintout = ItemPrintout.createBookFromTitleAndText( null, null, null ); - - // Impostor Printout recipes (to fool NEI) - ItemStack string = new ItemStack( Items.STRING, 1, 0 ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( multiplePrintout, new ItemStack[]{singlePrintout, singlePrintout, string} ) ); - - ItemStack leather = new ItemStack( Items.LEATHER, 1, 0 ); - GameRegistry.addRecipe( new ImpostorShapelessRecipe( bookPrintout, new ItemStack[]{leather, singlePrintout, string} ) ); - - // Pocket Computer - ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, null ); - GameRegistry.addRecipe( pocketComputer, - "XXX", "XYX", "XZX", - 'X', Blocks.STONE, - 'Y', Items.GOLDEN_APPLE, - 'Z', Blocks.GLASS_PANE - ); - - // Advanced Pocket Computer - ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, null ); - GameRegistry.addRecipe( advancedPocketComputer, - "XXX", "XYX", "XZX", - 'X', Items.GOLD_INGOT, - 'Y', Items.GOLDEN_APPLE, - 'Z', Blocks.GLASS_PANE - ); + registry.register( new PrintoutRecipe().setRegistryName( new ResourceLocation( "computercraft:printout" ) ) ); // Register pocket upgrades ComputerCraft.PocketUpgrades.wirelessModem = new PocketModem( false ); @@ -457,61 +357,52 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy ComputerCraftAPI.registerPocketUpgrade( ComputerCraft.PocketUpgrades.pocketSpeaker ); // Wireless Pocket Computer - GameRegistry.addRecipe( new PocketComputerUpgradeRecipe() ); + registry.register( new PocketComputerUpgradeRecipe().setRegistryName( new ResourceLocation( "computercraft:pocket_computer_upgrade" ) ) ); // Impostor Pocket Computer recipes (to fool NEI) - for (IPocketUpgrade upgrade : ComputerCraft.getVanillaPocketUpgrades()) + ItemStack pocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, null ); + ItemStack advancedPocketComputer = PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, null ); + for( IPocketUpgrade upgrade : ComputerCraft.getVanillaPocketUpgrades() ) { - GameRegistry.addRecipe( new ImpostorRecipe( - 1, 2, - new ItemStack[]{ upgrade.getCraftingItem(), pocketComputer }, - PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, upgrade ) - ) ); + registry.register( new ImpostorRecipe( + "computercraft:normal_pocket_upgrade", + 1, 2, + new ItemStack[] { upgrade.getCraftingItem(), pocketComputer }, + PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Normal, upgrade ) + ).setRegistryName( new ResourceLocation( "computercraft:normal_pocket_upgrade_" + upgrade.getUpgradeID().toString().replace( ':', '_' ) ) ) + ); - GameRegistry.addRecipe( new ImpostorRecipe( - 1, 2, - new ItemStack[]{ upgrade.getCraftingItem(), advancedPocketComputer }, - PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, upgrade ) - ) ); + registry.register( + new ImpostorRecipe( "computercraft:advanced_pocket_upgrade", + 1, 2, + new ItemStack[] { upgrade.getCraftingItem(), advancedPocketComputer }, + PocketComputerItemFactory.create( -1, null, -1, ComputerFamily.Advanced, upgrade ) + ).setRegistryName( new ResourceLocation( "computercraft:advanced_pocket_upgrade_" + upgrade.getUpgradeID().toString().replace( ':', '_' ) ) ) + ); } - - // Skulls (Easter Egg) - // Dan - NBTTagCompound tag = new NBTTagCompound(); - tag.setString( "SkullOwner", "dan200" ); - ItemStack danHead = new ItemStack( Items.SKULL, 1, 3 ); - danHead.setTagCompound( tag ); - GameRegistry.addShapelessRecipe( danHead, computer, new ItemStack( Items.SKULL, 1, 1 ) ); - - // Cloudy - tag = new NBTTagCompound(); - tag.setString( "SkullOwner", "Cloudhunter" ); - ItemStack cloudyHead = new ItemStack( Items.SKULL, 1, 3 ); - cloudyHead.setTagCompound( tag ); - GameRegistry.addShapelessRecipe( cloudyHead, monitor, new ItemStack( Items.SKULL, 1, 1 ) ); } - @Override - public void remap( FMLMissingMappingsEvent mappings ) + @SubscribeEvent + public void remapItems( RegistryEvent.MissingMappings mappings ) { - // We have to use mappings.getAll() as the mod ID is upper case but the domain lower. - for( FMLMissingMappingsEvent.MissingMapping mapping : mappings.getAll() ) + // We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower. + for( RegistryEvent.MissingMappings.Mapping mapping : mappings.getAllMappings() ) { - String domain = mapping.resourceLocation.getResourceDomain(); + String domain = mapping.key.getResourceDomain(); if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue; - String key = mapping.resourceLocation.getResourcePath(); + String key = mapping.key.getResourcePath(); if( key.equalsIgnoreCase( "CC-Computer" ) ) { - remap( mapping, ComputerCraft.Blocks.computer ); + mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.computer ) ); } else if( key.equalsIgnoreCase( "CC-Peripheral" ) ) { - remap( mapping, ComputerCraft.Blocks.peripheral ); + mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.peripheral ) ); } else if( key.equalsIgnoreCase( "CC-Cable" ) ) { - remap( mapping, ComputerCraft.Blocks.cable ); + mapping.remap( Item.getItemFromBlock( ComputerCraft.Blocks.cable ) ); } else if( key.equalsIgnoreCase( "diskExpanded" ) ) { @@ -528,41 +419,43 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy } } - private static void remap( FMLMissingMappingsEvent.MissingMapping mapping, Block block ) + @SubscribeEvent + public void remapBlocks( RegistryEvent.MissingMappings mappings ) { - if( mapping.type == GameRegistry.Type.BLOCK ) + // We have to use mappings.getAllMappings() as the mod ID is upper case but the domain lower. + for( RegistryEvent.MissingMappings.Mapping mapping : mappings.getAllMappings() ) { - mapping.remap( block ); - } - else - { - mapping.remap( Item.getItemFromBlock( block ) ); - } - } + String domain = mapping.key.getResourceDomain(); + if( !domain.equalsIgnoreCase( ComputerCraft.MOD_ID ) ) continue; - private void registerBlock( Block block, Item item, String name ) - { - GameRegistry.register( block.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); - GameRegistry.register( item.setRegistryName( new ResourceLocation( ComputerCraft.MOD_ID, name ) ) ); - } - - private void registerTileEntity( Class klass, String name ) - { - GameRegistry.registerTileEntityWithAlternatives( klass, ComputerCraft.LOWER_ID + " : " + name, name ); + String key = mapping.key.getResourcePath(); + if( key.equalsIgnoreCase( "CC-Computer" ) ) + { + mapping.remap( ComputerCraft.Blocks.computer ); + } + else if( key.equalsIgnoreCase( "CC-Peripheral" ) ) + { + mapping.remap( ComputerCraft.Blocks.peripheral ); + } + else if( key.equalsIgnoreCase( "CC-Cable" ) ) + { + mapping.remap( ComputerCraft.Blocks.cable ); + } + } } private void registerTileEntities() { // Tile Entities - registerTileEntity( TileComputer.class, "computer" ); - registerTileEntity( TileDiskDrive.class, "diskdrive" ); - registerTileEntity( TileWirelessModem.class, "wirelessmodem" ); - registerTileEntity( TileMonitor.class, "monitor" ); - registerTileEntity( TilePrinter.class, "ccprinter" ); - registerTileEntity( TileCable.class, "wiredmodem" ); - registerTileEntity( TileCommandComputer.class, "command_computer" ); - registerTileEntity( TileAdvancedModem.class, "advanced_modem" ); - registerTileEntity( TileSpeaker.class, "speaker" ); + 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" ); // Register peripheral providers ComputerCraftAPI.registerPeripheralProvider( new DefaultPeripheralProvider() ); diff --git a/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java b/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java index 55adffbc7..3baa8db0a 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java +++ b/src/main/java/dan200/computercraft/shared/proxy/ICCTurtleProxy.java @@ -10,7 +10,6 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade; import dan200.computercraft.shared.util.IEntityDropConsumer; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; import net.minecraft.util.NonNullList; import javax.annotation.Nonnull; @@ -19,7 +18,6 @@ public interface ICCTurtleProxy { void preInit(); void init(); - void remap( FMLMissingMappingsEvent mappings); void registerTurtleUpgrade( ITurtleUpgrade upgrade ); ITurtleUpgrade getTurtleUpgrade( String id ); diff --git a/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java b/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java index 359a027e2..38faf621f 100644 --- a/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java +++ b/src/main/java/dan200/computercraft/shared/proxy/IComputerCraftProxy.java @@ -18,7 +18,6 @@ import net.minecraft.util.EnumHand; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; import javax.annotation.Nonnull; import java.io.File; @@ -27,7 +26,6 @@ public interface IComputerCraftProxy { void preInit(); void init(); - void remap( FMLMissingMappingsEvent mappings); boolean isClient(); boolean getGlobalCursorBlink(); diff --git a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java index 382d6d984..67056e18e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/blocks/TileTurtle.java @@ -156,7 +156,7 @@ public class TileTurtle extends TileComputerBase } @Override - public void getDroppedItems( @Nonnull List drops, boolean creative ) + public void getDroppedItems( @Nonnull NonNullList drops, boolean creative ) { IComputer computer = getComputer(); if( !creative || (computer != null && computer.getLabel() != null) ) @@ -258,8 +258,8 @@ public class TileTurtle extends TileComputerBase { Vec3d offset = getRenderOffset( 1.0f ); return new AxisAlignedBB( - offset.xCoord + 0.125, offset.yCoord + 0.125, offset.zCoord + 0.125, - offset.xCoord + 0.875, offset.yCoord + 0.875, offset.zCoord + 0.875 + offset.x + 0.125, offset.y + 0.125, offset.z + 0.125, + offset.x + 0.875, offset.y + 0.875, offset.z + 0.875 ); } diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java index 23fa1e182..6e73f115e 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleBrain.java @@ -553,9 +553,9 @@ public class TurtleBrain implements ITurtleAccess Vec3d offset = getRenderOffset( f ); BlockPos pos = m_owner.getPos(); return new Vec3d( - pos.getX() + 0.5 + offset.xCoord, - pos.getY() + 0.5 + offset.yCoord, - pos.getZ() + 0.5 + offset.zCoord + pos.getX() + 0.5 + offset.x, + pos.getY() + 0.5 + offset.y, + pos.getZ() + 0.5 + offset.z ); } @@ -1177,9 +1177,9 @@ public class TurtleBrain implements ITurtleAccess Vec3d position = getVisualPosition( 1.0f ); if( position != null ) { - double x = position.xCoord + world.rand.nextGaussian() * 0.1; - double y = position.yCoord + 0.5 + world.rand.nextGaussian() * 0.1; - double z = position.zCoord + world.rand.nextGaussian() * 0.1; + double x = position.x + world.rand.nextGaussian() * 0.1; + double y = position.y + 0.5 + world.rand.nextGaussian() * 0.1; + double z = position.z + world.rand.nextGaussian() * 0.1; world.spawnParticle( EnumParticleTypes.HEART, x, y, z, world.rand.nextGaussian() * 0.02, diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java index 5fe350ec0..102a91172 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleCompareCommand.java @@ -15,13 +15,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.ReflectionHelper; import javax.annotation.Nonnull; import java.lang.reflect.Method; -import java.util.List; public class TurtleCompareCommand implements ITurtleCommand { @@ -77,8 +77,9 @@ public class TurtleCompareCommand implements ITurtleCommand // (try 5 times to try and beat random number generators) for( int i=0; (i<5) && lookAtStack.isEmpty(); ++i ) { - List drops = lookAtBlock.getDrops( world, newPosition, lookAtState, 0 ); - if( drops != null && drops.size() > 0 ) + NonNullList drops = NonNullList.create(); + lookAtBlock.getDrops( drops, world, newPosition, lookAtState, 0 ); + if( drops.size() > 0 ) { for( ItemStack drop : drops ) { diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java index c362a558b..09154546a 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtlePlaceCommand.java @@ -240,7 +240,7 @@ public class TurtlePlaceCommand implements ITurtleCommand // Place on the entity boolean placed = false; - EnumActionResult cancelResult = ForgeHooks.onInteractEntityAtAction( turtlePlayer, hitEntity, hitPos, EnumHand.MAIN_HAND ); + EnumActionResult cancelResult = ForgeHooks.onInteractEntityAt( turtlePlayer, hitEntity, hitPos, EnumHand.MAIN_HAND ); if( cancelResult == null ) { cancelResult = hitEntity.applyPlayerInteraction( turtlePlayer, hitPos, EnumHand.MAIN_HAND ); @@ -253,7 +253,7 @@ public class TurtlePlaceCommand implements ITurtleCommand else { // See EntityPlayer.interactOn - cancelResult = ForgeHooks.onInteractEntityAction( turtlePlayer, hitEntity, EnumHand.MAIN_HAND ); + cancelResult = ForgeHooks.onInteractEntity( turtlePlayer, hitEntity, EnumHand.MAIN_HAND ); if( cancelResult == EnumActionResult.SUCCESS ) { placed = true; @@ -391,7 +391,7 @@ public class TurtlePlaceCommand implements ITurtleCommand if( !placed && (item instanceof ItemBucket || item instanceof ItemBoat || item instanceof ItemLilyPad || item instanceof ItemGlassBottle) ) { - EnumActionResult actionResult = ForgeHooks.onItemRightClickAction( turtlePlayer, EnumHand.MAIN_HAND ); + EnumActionResult actionResult = ForgeHooks.onItemRightClick( turtlePlayer, EnumHand.MAIN_HAND ); if( actionResult == EnumActionResult.SUCCESS ) { placed = true; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java index f327e9eb8..a9db1f9b0 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleSuckCommand.java @@ -102,7 +102,7 @@ public class TurtleSuckCommand implements ITurtleCommand // Suck up the item foundItems = true; EntityItem entityItem = (EntityItem) entity; - ItemStack stack = entityItem.getEntityItem().copy(); + ItemStack stack = entityItem.getItem().copy(); ItemStack storeStack; ItemStack leaveStack; if( stack.getCount() > m_quantity ) @@ -125,16 +125,16 @@ public class TurtleSuckCommand implements ITurtleCommand } else if( remainder.isEmpty() ) { - entityItem.setEntityItemStack( leaveStack ); + entityItem.setItem( leaveStack ); } else if( leaveStack.isEmpty() ) { - entityItem.setEntityItemStack( remainder ); + entityItem.setItem( remainder ); } else { leaveStack.grow( remainder.getCount() ); - entityItem.setEntityItemStack( leaveStack ); + entityItem.setItem( leaveStack ); } break; } diff --git a/src/main/java/dan200/computercraft/shared/turtle/entity/TurtleVisionCamera.java b/src/main/java/dan200/computercraft/shared/turtle/entity/TurtleVisionCamera.java index 4c2ce5f89..c8af85dec 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/entity/TurtleVisionCamera.java +++ b/src/main/java/dan200/computercraft/shared/turtle/entity/TurtleVisionCamera.java @@ -60,17 +60,17 @@ public class TurtleVisionCamera extends EntityLivingBase private void applyPos() { Vec3d prevPos = m_turtle.getVisualPosition( 0.0f ); - this.lastTickPosX = this.prevPosX = prevPos.xCoord; - this.lastTickPosY = this.prevPosY = prevPos.yCoord; - this.lastTickPosZ = this.prevPosZ = prevPos.zCoord; + this.lastTickPosX = this.prevPosX = prevPos.x; + this.lastTickPosY = this.prevPosY = prevPos.y; + this.lastTickPosZ = this.prevPosZ = prevPos.z; this.prevRotationPitch = 0.0f; this.prevRotationYaw = m_turtle.getVisualYaw( 0.0f ); this.prevCameraPitch = 0.0f; Vec3d pos = m_turtle.getVisualPosition( 1.0f ); - this.posX = pos.xCoord; - this.posY = pos.yCoord; - this.posZ = pos.zCoord; + this.posX = pos.x; + this.posY = pos.y; + this.posZ = pos.z; this.rotationPitch = 0.0f; this.rotationYaw = m_turtle.getVisualYaw( 1.0f ); this.cameraPitch = 0.0f; diff --git a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java index 91e2efd30..3b3b60dad 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java +++ b/src/main/java/dan200/computercraft/shared/turtle/inventory/ContainerTurtle.java @@ -92,7 +92,7 @@ public class ContainerTurtle extends Container private void sendStateToPlayer( IContainerListener icrafting ) { int selectedSlot = m_turtle.getSelectedSlot(); - icrafting.sendProgressBarUpdate( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot ); + icrafting.sendWindowProperty( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot ); } @Override @@ -112,7 +112,7 @@ public class ContainerTurtle extends Container { if( m_selectedSlot != selectedSlot ) { - listener.sendProgressBarUpdate( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot ); + listener.sendWindowProperty( this, PROGRESS_ID_SELECTED_SLOT, selectedSlot ); } } m_selectedSlot = selectedSlot; diff --git a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java index 4dde77fbf..8b7fc2796 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java +++ b/src/main/java/dan200/computercraft/shared/turtle/items/ItemTurtleBase.java @@ -42,8 +42,9 @@ public abstract class ItemTurtleBase extends ItemComputerBase implements ITurtle public abstract ItemStack create( int id, String label, int colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, int fuelLevel, ResourceLocation overlay ); @Override - public void getSubItems( @Nonnull Item itemID, @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) + public void getSubItems( @Nullable CreativeTabs tabs, @Nonnull NonNullList list ) { + if( !isInCreativeTab( tabs ) ) return; NonNullList all = NonNullList.create(); ComputerCraft.addAllUpgradedTurtles( all ); for( ItemStack stack : all ) diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java index dc6103ffc..1cf703185 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleRecipe.java @@ -6,43 +6,38 @@ package dan200.computercraft.shared.turtle.recipes; +import com.google.gson.JsonObject; +import com.google.gson.JsonSyntaxException; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.items.IComputerItem; import dan200.computercraft.shared.turtle.items.TurtleItemFactory; +import dan200.computercraft.shared.util.RecipeUtil; import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.item.crafting.ShapedRecipes; +import net.minecraft.util.JsonUtils; import net.minecraft.util.NonNullList; import net.minecraft.world.World; -import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.crafting.CraftingHelper; +import net.minecraftforge.common.crafting.IRecipeFactory; +import net.minecraftforge.common.crafting.JsonContext; import javax.annotation.Nonnull; -public class TurtleRecipe implements IRecipe +public class TurtleRecipe extends ShapedRecipes { - private final Item[] m_recipe; + private final NonNullList m_recipe; private final ComputerFamily m_family; - - public TurtleRecipe( Item[] recipe, ComputerFamily family ) + + public TurtleRecipe( String group, int width, int height, NonNullList recipe, ComputerFamily family ) { + super( group, width, height, recipe, TurtleItemFactory.create( -1, null, -1, family, null, null, 0, null ) ); m_recipe = recipe; m_family = family; } - @Override - public int getRecipeSize() - { - return 9; - } - - @Nonnull - @Override - public ItemStack getRecipeOutput() - { - return TurtleItemFactory.create( -1, null, -1, m_family, null, null, 0, null ); - } - @Override public boolean matches( @Nonnull InventoryCrafting _inventory, @Nonnull World world ) { @@ -56,34 +51,28 @@ public class TurtleRecipe implements IRecipe // See if we match the recipe, and extract the input computercraft ID int computerID = -1; String label = null; - for( int y=0; y<3; ++y ) + for( int y = 0; y < 3; ++y ) { - for( int x=0; x<3; ++x ) + for( int x = 0; x < 3; ++x ) { - ItemStack item = inventory.getStackInRowAndColumn(x, y); - if( !item.isEmpty() && item.getItem() == m_recipe[ x + y*3 ] ) + ItemStack item = inventory.getStackInRowAndColumn( x, y ); + Ingredient target = m_recipe.get( x + y * 3 ); + + if( item.getItem() instanceof IComputerItem ) { - if( item.getItem() instanceof IComputerItem ) - { - IComputerItem itemComputer = (IComputerItem)item.getItem(); - if( m_family == ComputerFamily.Beginners || itemComputer.getFamily( item ) == m_family ) - { - computerID = itemComputer.getComputerID( item ); - label = itemComputer.getLabel( item ); - } - else - { - return ItemStack.EMPTY; - } - } + IComputerItem itemComputer = (IComputerItem) item.getItem(); + if( itemComputer.getFamily( item ) != m_family ) return ItemStack.EMPTY; + + computerID = itemComputer.getComputerID( item ); + label = itemComputer.getLabel( item ); } - else + else if( !target.apply( item ) ) { return ItemStack.EMPTY; } } } - + // Build a turtle with the same ID the computer had // Construct the new stack if( m_family != ComputerFamily.Beginners ) @@ -96,16 +85,26 @@ public class TurtleRecipe implements IRecipe } } - @Nonnull - @Override - public NonNullList getRemainingItems( @Nonnull InventoryCrafting inventoryCrafting ) + public static class Factory implements IRecipeFactory { - NonNullList results = NonNullList.withSize( inventoryCrafting.getSizeInventory(), ItemStack.EMPTY ); - for( int i = 0; i < results.size(); ++i ) + @Override + public IRecipe parse( JsonContext context, JsonObject json ) { - ItemStack stack = inventoryCrafting.getStackInSlot( i ); - results.set( i, ForgeHooks.getContainerItem( stack ) ); + String group = JsonUtils.getString( json, "group", "" ); + + String familyName = JsonUtils.getString( json, "family" ); + ComputerFamily family; + try + { + family = ComputerFamily.valueOf( familyName ); + } + catch( IllegalArgumentException e ) + { + throw new JsonSyntaxException( "Unknown computer family '" + familyName + "'" ); + } + + CraftingHelper.ShapedPrimer primer = RecipeUtil.getPrimer( context, json ); + return new TurtleRecipe( group, primer.width, primer.height, primer.input, family ); } - return results; } } diff --git a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java index 371a52424..6cedad145 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java +++ b/src/main/java/dan200/computercraft/shared/turtle/recipes/TurtleUpgradeRecipe.java @@ -13,7 +13,6 @@ import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.proxy.CCTurtleProxyCommon; import dan200.computercraft.shared.turtle.items.ITurtleItem; import dan200.computercraft.shared.turtle.items.TurtleItemFactory; -import dan200.computercraft.shared.util.Colour; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; @@ -21,19 +20,26 @@ import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.registries.IForgeRegistryEntry; import javax.annotation.Nonnull; -public class TurtleUpgradeRecipe implements IRecipe +public class TurtleUpgradeRecipe extends IForgeRegistryEntry.Impl implements IRecipe { public TurtleUpgradeRecipe() { } @Override - public int getRecipeSize() + public boolean canFit( int x, int y ) { - return 3; + return x >= 3 && y >= 1; + } + + @Override + public boolean isHidden() + { + return true; } @Nonnull diff --git a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java index 493687098..696541feb 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java +++ b/src/main/java/dan200/computercraft/shared/turtle/upgrades/TurtleInventoryCrafting.java @@ -59,7 +59,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting } // Check the actual crafting - return CraftingManager.getInstance().findMatchingRecipe( this, m_turtle.getWorld() ); + return CraftingManager.findMatchingResult( this, m_turtle.getWorld() ); } public ArrayList doCrafting( World world, int maxCount ) @@ -123,7 +123,7 @@ public class TurtleInventoryCrafting extends InventoryCrafting results.add( result ); // Consume resources from the inventory - NonNullList remainingItems = CraftingManager.getInstance().getRemainingItems( this, world ); + NonNullList remainingItems = CraftingManager.getRemainingItems( this, world ); for( int n=0; n drops = block.getDrops( world, pos, world.getBlockState( pos ), 0 ); + NonNullList drops = NonNullList.create(); + block.getDrops( drops, world, pos, world.getBlockState( pos ), 0 ); double chance = ForgeEventFactory.fireBlockHarvesting( drops, world, pos, state, 0, 1, false, player ); for( int i = drops.size() - 1; i >= 0; i-- ) diff --git a/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java b/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java index e56fd5d3b..8105b026b 100644 --- a/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java +++ b/src/main/java/dan200/computercraft/shared/util/ImpostorRecipe.java @@ -5,18 +5,39 @@ */ package dan200.computercraft.shared.util; + +import com.google.gson.JsonObject; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.item.crafting.ShapedRecipes; +import net.minecraft.util.JsonUtils; +import net.minecraft.util.NonNullList; import net.minecraft.world.World; +import net.minecraftforge.common.crafting.CraftingHelper; +import net.minecraftforge.common.crafting.IRecipeFactory; +import net.minecraftforge.common.crafting.JsonContext; import javax.annotation.Nonnull; public class ImpostorRecipe extends ShapedRecipes { - public ImpostorRecipe( int width, int height, ItemStack[] ingredients, @Nonnull ItemStack result ) + public ImpostorRecipe( @Nonnull String group, int width, int height, NonNullList ingredients, @Nonnull ItemStack result ) { - super( width, height, ingredients, result ); + super( group, width, height, ingredients, result ); + } + + public ImpostorRecipe( @Nonnull String group, int width, int height, ItemStack[] ingredients, @Nonnull ItemStack result ) + { + super( group, width, height, convert( ingredients ), result ); + } + + private static NonNullList convert( ItemStack[] items ) + { + NonNullList ingredients = NonNullList.withSize( items.length, Ingredient.EMPTY ); + for( int i = 0; i < items.length; i++ ) ingredients.set( i, Ingredient.fromStacks( items[ i ] ) ); + return ingredients; } @Override @@ -24,11 +45,23 @@ public class ImpostorRecipe extends ShapedRecipes { return false; } - + @Nonnull @Override public ItemStack getCraftingResult( @Nonnull InventoryCrafting _inventory ) { return ItemStack.EMPTY; } + + public static class Factory implements IRecipeFactory + { + @Override + public IRecipe parse( JsonContext ctx, JsonObject json ) + { + String group = JsonUtils.getString( json, "group", "" ); + CraftingHelper.ShapedPrimer primer = RecipeUtil.getPrimer( ctx, json ); + ItemStack result = CraftingHelper.getItemStack( JsonUtils.getJsonObject( json, "result" ), ctx ); + return new ImpostorRecipe( group, primer.width, primer.height, primer.input, result ); + } + } } diff --git a/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java b/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java index ee545133f..6caa072c5 100644 --- a/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java +++ b/src/main/java/dan200/computercraft/shared/util/ImpostorShapelessRecipe.java @@ -6,20 +6,38 @@ package dan200.computercraft.shared.util; +import com.google.gson.JsonObject; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; +import net.minecraft.util.JsonUtils; +import net.minecraft.util.NonNullList; import net.minecraft.world.World; +import net.minecraftforge.common.crafting.IRecipeFactory; +import net.minecraftforge.common.crafting.JsonContext; import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.Arrays; public class ImpostorShapelessRecipe extends ShapelessRecipes { - public ImpostorShapelessRecipe( @Nonnull ItemStack result, ItemStack[] ingredients ) + public ImpostorShapelessRecipe( @Nonnull String group, @Nonnull ItemStack result, NonNullList ingredients ) { - super( result, new ArrayList(Arrays.asList( ingredients ))); + super( group, result, ingredients ); + } + + public ImpostorShapelessRecipe( @Nonnull String group, @Nonnull ItemStack result, ItemStack[] ingredients ) + { + super( group, result, convert( ingredients ) ); + } + + private static NonNullList convert( ItemStack[] items ) + { + NonNullList ingredients = NonNullList.withSize( items.length, Ingredient.EMPTY ); + for( int i = 0; i < items.length; i++ ) ingredients.set( i, Ingredient.fromStacks( items[ i ] ) ); + return ingredients; } @Override @@ -30,8 +48,20 @@ public class ImpostorShapelessRecipe extends ShapelessRecipes @Nonnull @Override - public ItemStack getCraftingResult( InventoryCrafting _inventory ) + public ItemStack getCraftingResult( InventoryCrafting inventory ) { return ItemStack.EMPTY; } + + public static class Factory implements IRecipeFactory + { + @Override + public IRecipe parse( JsonContext context, JsonObject json ) + { + String group = JsonUtils.getString( json, "group", "" ); + NonNullList ings = RecipeUtil.getIngredients( context, json ); + ItemStack itemstack = ShapedRecipes.deserializeItem( JsonUtils.getJsonObject( json, "result" ), true ); + return new ImpostorShapelessRecipe( group, itemstack, ings ); + } + } } diff --git a/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java new file mode 100644 index 000000000..e222a06cc --- /dev/null +++ b/src/main/java/dan200/computercraft/shared/util/RecipeUtil.java @@ -0,0 +1,105 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ + +package dan200.computercraft.shared.util; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import com.google.gson.*; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.util.JsonUtils; +import net.minecraft.util.NonNullList; +import net.minecraftforge.common.crafting.CraftingHelper; +import net.minecraftforge.common.crafting.JsonContext; + +import java.util.Map; +import java.util.Set; + +public class RecipeUtil +{ + public static CraftingHelper.ShapedPrimer getPrimer( JsonContext context, JsonObject json ) + { + Map ingMap = Maps.newHashMap(); + for( Map.Entry entry : JsonUtils.getJsonObject( json, "key" ).entrySet() ) + { + if( entry.getKey().length() != 1 ) + { + throw new JsonSyntaxException( "Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only)." ); + } + if( " ".equals( entry.getKey() ) ) + { + throw new JsonSyntaxException( "Invalid key entry: ' ' is a reserved symbol." ); + } + + ingMap.put( entry.getKey().charAt( 0 ), CraftingHelper.getIngredient( entry.getValue(), context ) ); + } + + ingMap.put( ' ', Ingredient.EMPTY ); + + JsonArray patternJ = JsonUtils.getJsonArray( json, "pattern" ); + + if( patternJ.size() == 0 ) + throw new JsonSyntaxException( "Invalid pattern: empty pattern not allowed" ); + + String[] pattern = new String[ patternJ.size() ]; + for( int x = 0; x < pattern.length; ++x ) + { + String line = JsonUtils.getString( patternJ.get( x ), "pattern[" + x + "]" ); + if( x > 0 && pattern[ 0 ].length() != line.length() ) + { + throw new JsonSyntaxException( "Invalid pattern: each row must be the same width" ); + } + pattern[ x ] = line; + } + + CraftingHelper.ShapedPrimer primer = new CraftingHelper.ShapedPrimer(); + primer.width = pattern[ 0 ].length(); + primer.height = pattern.length; + primer.mirrored = false; + primer.input = NonNullList.withSize( primer.width * primer.height, Ingredient.EMPTY ); + + Set keys = Sets.newHashSet( ingMap.keySet() ); + keys.remove( ' ' ); + + int x = 0; + for( String line : pattern ) + { + for( char chr : line.toCharArray() ) + { + Ingredient ing = ingMap.get( chr ); + if( ing == null ) + { + throw new JsonSyntaxException( "Pattern references symbol '" + chr + "' but it's not defined in the key" ); + } + primer.input.set( x++, ing ); + keys.remove( chr ); + } + } + + if( !keys.isEmpty() ) + { + throw new JsonSyntaxException( "Key defines symbols that aren't used in pattern: " + keys ); + } + + return primer; + } + + public static NonNullList getIngredients( JsonContext context, JsonObject json ) + { + NonNullList ings = NonNullList.create(); + for( JsonElement ele : JsonUtils.getJsonArray( json, "ingredients" ) ) + { + ings.add( CraftingHelper.getIngredient( ele, context ) ); + } + + if( ings.isEmpty() ) + { + throw new JsonParseException( "No ingredients for recipe" ); + } + + return ings; + } +} diff --git a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java index 861d5bf56..ff7289a4d 100644 --- a/src/main/java/dan200/computercraft/shared/util/WorldUtil.java +++ b/src/main/java/dan200/computercraft/shared/util/WorldUtil.java @@ -36,27 +36,27 @@ public class WorldUtil public static Pair rayTraceEntities( World world, Vec3d vecStart, Vec3d vecDir, double distance ) { - Vec3d vecEnd = vecStart.addVector( vecDir.xCoord * distance, vecDir.yCoord * distance, vecDir.zCoord * distance ); + Vec3d vecEnd = vecStart.addVector( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance ); // Raycast for blocks RayTraceResult result = world.rayTraceBlocks( vecStart.addVector(0.0,0.0,0.0), vecEnd.addVector(0.0,0.0,0.0) ); if( result != null && result.typeOfHit == RayTraceResult.Type.BLOCK ) { distance = vecStart.distanceTo( result.hitVec ); - vecEnd = vecStart.addVector( vecDir.xCoord * distance, vecDir.yCoord * distance, vecDir.zCoord * distance ); + vecEnd = vecStart.addVector( vecDir.x * distance, vecDir.y * distance, vecDir.z * distance ); } // Check for entities - float xStretch = (Math.abs(vecDir.xCoord) > 0.25f) ? 0.0f : 1.0f; - float yStretch = (Math.abs(vecDir.yCoord) > 0.25f) ? 0.0f : 1.0f; - float zStretch = (Math.abs(vecDir.zCoord) > 0.25f) ? 0.0f : 1.0f; + float xStretch = (Math.abs(vecDir.x) > 0.25f) ? 0.0f : 1.0f; + float yStretch = (Math.abs(vecDir.y) > 0.25f) ? 0.0f : 1.0f; + float zStretch = (Math.abs(vecDir.z) > 0.25f) ? 0.0f : 1.0f; AxisAlignedBB bigBox = new AxisAlignedBB( - Math.min(vecStart.xCoord, vecEnd.xCoord) - 0.375f * xStretch, - Math.min(vecStart.yCoord, vecEnd.yCoord) - 0.375f * yStretch, - Math.min(vecStart.zCoord, vecEnd.zCoord) - 0.375f * zStretch, - Math.max(vecStart.xCoord, vecEnd.xCoord) + 0.375f * xStretch, - Math.max(vecStart.yCoord, vecEnd.yCoord) + 0.375f * yStretch, - Math.max(vecStart.zCoord, vecEnd.zCoord) + 0.375f * zStretch + Math.min(vecStart.x, vecEnd.x) - 0.375f * xStretch, + Math.min(vecStart.y, vecEnd.y) - 0.375f * yStretch, + Math.min(vecStart.z, vecEnd.z) - 0.375f * zStretch, + Math.max(vecStart.x, vecEnd.x) + 0.375f * xStretch, + Math.max(vecStart.y, vecEnd.y) + 0.375f * yStretch, + Math.max(vecStart.z, vecEnd.z) + 0.375f * zStretch ); Entity closest = null; @@ -79,7 +79,7 @@ public class WorldUtil } } - if( littleBox.isVecInside( vecStart ) ) + if( littleBox.contains( vecStart ) ) { closest = entity; closestDist = 0.0f; @@ -96,7 +96,7 @@ public class WorldUtil closestDist = dist; } } - else if( littleBox.intersectsWith( bigBox ) ) + else if( littleBox.intersects( bigBox ) ) { if( closest == null ) { @@ -107,7 +107,7 @@ public class WorldUtil } if( closest != null && closestDist <= distance ) { - Vec3d closestPos = vecStart.addVector( vecDir.xCoord * closestDist, vecDir.yCoord * closestDist, vecDir.zCoord * closestDist ); + Vec3d closestPos = vecStart.addVector( vecDir.x * closestDist, vecDir.y * closestDist, vecDir.z * closestDist ); return Pair.of( closest, closestPos ); } return null; diff --git a/src/main/resources/assets/computercraft/recipes/_factories.json b/src/main/resources/assets/computercraft/recipes/_factories.json new file mode 100644 index 000000000..8f525a27a --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/_factories.json @@ -0,0 +1,7 @@ +{ + "recipes" : { + "impostor_shaped" : "dan200.computercraft.shared.util.ImpostorRecipe$Factory", + "impostor_shapeless" : "dan200.computercraft.shared.util.ImpostorShapelessRecipe$Factory", + "turtle" : "dan200.computercraft.shared.turtle.recipes.TurtleRecipe$Factory" + } +} diff --git a/src/main/resources/assets/computercraft/recipes/advanced_computer.json b/src/main/resources/assets/computercraft/recipes/advanced_computer.json new file mode 100644 index 000000000..a21e38f23 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/advanced_computer.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#R#", + "#G#" + ], + "key": { + "#": { "item": "minecraft:gold_ingot" }, + "R": { "item": "minecraft:redstone" }, + "G": { "item": "minecraft:glass_pane" } + }, + "result": { "item": "computercraft:computer", "data": 16384 } +} diff --git a/src/main/resources/assets/computercraft/recipes/advanced_monitor.json b/src/main/resources/assets/computercraft/recipes/advanced_monitor.json new file mode 100644 index 000000000..50eb01147 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/advanced_monitor.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#G#", + "###" + ], + "key": { + "#": { "item": "minecraft:gold_ingot" }, + "G": { "item": "minecraft:glass_pane" } + }, + "result": { "item": "computercraft:peripheral", "data": 4 } +} diff --git a/src/main/resources/assets/computercraft/recipes/advanced_pocket_computer.json b/src/main/resources/assets/computercraft/recipes/advanced_pocket_computer.json new file mode 100644 index 000000000..7da96111b --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/advanced_pocket_computer.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#A#", + "#G#" + ], + "key": { + "#": { "item": "minecraft:gold_ingot" }, + "G": { "item": "minecraft:glass_pane" }, + "A": { "item": "minecraft:golden_apple", "data": 0 } + }, + "result": { "item": "computercraft:pocket_computer", "data": 1 } +} diff --git a/src/main/resources/assets/computercraft/recipes/advanced_turtle.json b/src/main/resources/assets/computercraft/recipes/advanced_turtle.json new file mode 100644 index 000000000..ec2fa8c0f --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/advanced_turtle.json @@ -0,0 +1,14 @@ +{ + "type": "computercraft:turtle", + "pattern": [ + "###", + "#C#", + "#I#" + ], + "key": { + "#": { "item": "minecraft:gold_ingot" }, + "C": { "item": "computercraft:computer", "data": 16384 }, + "I": { "item": "minecraft:chest" } + }, + "family": "Advanced" +} diff --git a/src/main/resources/assets/computercraft/recipes/cable.json b/src/main/resources/assets/computercraft/recipes/cable.json new file mode 100644 index 000000000..5b49136bf --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/cable.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + " # ", + "#R#", + " # " + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "R": { "item": "minecraft:redstone" } + }, + "result": { "item": "computercraft:cable", "data": 0, "count": 6 } +} diff --git a/src/main/resources/assets/computercraft/recipes/command_computer.json b/src/main/resources/assets/computercraft/recipes/command_computer.json new file mode 100644 index 000000000..e5a5e1d89 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/command_computer.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#C#", + "#G#" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "C": { "item": "minecraft:command_block" }, + "G": { "item": "minecraft:glass_pane" } + }, + "result": { "item": "computercraft:command_computer", "data": 0 } +} diff --git a/src/main/resources/assets/computercraft/recipes/disk_drive.json b/src/main/resources/assets/computercraft/recipes/disk_drive.json new file mode 100644 index 000000000..3c44eba9b --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/disk_drive.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#R#", + "#R#" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "R": { "item": "minecraft:redstone" } + }, + "result": { "item": "computercraft:peripheral", "data": 0 } +} diff --git a/src/main/resources/assets/computercraft/recipes/disk_impostor.json b/src/main/resources/assets/computercraft/recipes/disk_impostor.json new file mode 100644 index 000000000..3eafce782 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/disk_impostor.json @@ -0,0 +1,8 @@ +{ + "type": "computercraft:impostor_shapeless", + "ingredients": [ + { "item": "minecraft:redstone" }, + { "item": "minecraft:paper" } + ], + "result": { "item": "computercraft:disk", "data": 0 } +} diff --git a/src/main/resources/assets/computercraft/recipes/ender_modem.json b/src/main/resources/assets/computercraft/recipes/ender_modem.json new file mode 100644 index 000000000..1f861819c --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/ender_modem.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#E#", + "###" + ], + "key": { + "#": { "item": "minecraft:gold_ingot" }, + "E": { "item": "minecraft:ender_eye" } + }, + "result": { "item": "computercraft:advanced_modem", "data": 0 } +} diff --git a/src/main/resources/assets/computercraft/recipes/normal_computer.json b/src/main/resources/assets/computercraft/recipes/normal_computer.json new file mode 100644 index 000000000..057784859 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/normal_computer.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#R#", + "#G#" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "R": { "item": "minecraft:redstone" }, + "G": { "item": "minecraft:glass_pane" } + }, + "result": { "item": "computercraft:computer", "data": 0 } +} diff --git a/src/main/resources/assets/computercraft/recipes/normal_monitor.json b/src/main/resources/assets/computercraft/recipes/normal_monitor.json new file mode 100644 index 000000000..1e71d055f --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/normal_monitor.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#G#", + "###" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "G": { "item": "minecraft:glass_pane" } + }, + "result": { "item": "computercraft:peripheral", "data": 2 } +} diff --git a/src/main/resources/assets/computercraft/recipes/normal_pocket_computer.json b/src/main/resources/assets/computercraft/recipes/normal_pocket_computer.json new file mode 100644 index 000000000..7b436e750 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/normal_pocket_computer.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#A#", + "#G#" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "G": { "item": "minecraft:glass_pane" }, + "A": { "item": "minecraft:golden_apple", "data": 0 } + }, + "result": { "item": "computercraft:pocket_computer", "data": 0 } +} diff --git a/src/main/resources/assets/computercraft/recipes/normal_turtle.json b/src/main/resources/assets/computercraft/recipes/normal_turtle.json new file mode 100644 index 000000000..2962f2cc4 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/normal_turtle.json @@ -0,0 +1,14 @@ +{ + "type": "computercraft:turtle", + "pattern": [ + "###", + "#C#", + "#I#" + ], + "key": { + "#": { "item": "minecraft:iron_ingot" }, + "C": { "item": "computercraft:computer", "data": 0 }, + "I": { "item": "minecraft:chest" } + }, + "family": "Normal" +} diff --git a/src/main/resources/assets/computercraft/recipes/printed_book.json b/src/main/resources/assets/computercraft/recipes/printed_book.json new file mode 100644 index 000000000..28b993011 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/printed_book.json @@ -0,0 +1,9 @@ +{ + "type": "computercraft:impostor_shapeless", + "ingredients": [ + { "item": "minecraft:leather" }, + { "item": "computercraft:printout", "data": 0 }, + { "item": "minecraft:string" } + ], + "result": { "item": "computercraft:printout", "data": 2 } +} diff --git a/src/main/resources/assets/computercraft/recipes/printed_pages.json b/src/main/resources/assets/computercraft/recipes/printed_pages.json new file mode 100644 index 000000000..ed3aa01a0 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/printed_pages.json @@ -0,0 +1,9 @@ +{ + "type": "computercraft:impostor_shapeless", + "ingredients": [ + { "item": "computercraft:printout", "data": 0 }, + { "item": "computercraft:printout", "data": 0 }, + { "item": "minecraft:string" } + ], + "result": { "item": "computercraft:printout", "data": 1 } +} diff --git a/src/main/resources/assets/computercraft/recipes/printer.json b/src/main/resources/assets/computercraft/recipes/printer.json new file mode 100644 index 000000000..9873cdec6 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/printer.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#R#", + "#D#" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "R": { "item": "minecraft:redstone" }, + "D": { "item": "minecraft:dye", "data": 0 } + }, + "result": { "item": "computercraft:peripheral", "data": 3 } +} diff --git a/src/main/resources/assets/computercraft/recipes/skull_cloudy.json b/src/main/resources/assets/computercraft/recipes/skull_cloudy.json new file mode 100644 index 000000000..c1b431e78 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/skull_cloudy.json @@ -0,0 +1,12 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { "item": "minecraft:skull", "data": 1 }, + { "item": "computercraft:peripheral", "data": 2 } + ], + "result": { + "item": "minecraft:skull", + "data": 3, + "nbt": { "SkullOwner": "Cloudhunter" } + } +} diff --git a/src/main/resources/assets/computercraft/recipes/skull_dan200.json b/src/main/resources/assets/computercraft/recipes/skull_dan200.json new file mode 100644 index 000000000..6e3bd33b5 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/skull_dan200.json @@ -0,0 +1,12 @@ +{ + "type": "minecraft:crafting_shapeless", + "ingredients": [ + { "item": "minecraft:skull", "data": 1 }, + { "item": "computercraft:computer", "data": 0 } + ], + "result": { + "item": "minecraft:skull", + "data": 3, + "nbt": { "SkullOwner": "dan200" } + } +} diff --git a/src/main/resources/assets/computercraft/recipes/speaker.json b/src/main/resources/assets/computercraft/recipes/speaker.json new file mode 100644 index 000000000..8d3b2ad3d --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/speaker.json @@ -0,0 +1,14 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#N#", + "#R#" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "R": { "item": "minecraft:redstone" }, + "N": { "item": "minecraft:noteblock" } + }, + "result": { "item": "computercraft:peripheral", "data": 5 } +} diff --git a/src/main/resources/assets/computercraft/recipes/wired_modem.json b/src/main/resources/assets/computercraft/recipes/wired_modem.json new file mode 100644 index 000000000..8df60d37d --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/wired_modem.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#R#", + "###" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "R": { "item": "minecraft:redstone" } + }, + "result": { "item": "computercraft:cable", "data": 1 } +} diff --git a/src/main/resources/assets/computercraft/recipes/wireless_modem.json b/src/main/resources/assets/computercraft/recipes/wireless_modem.json new file mode 100644 index 000000000..372285a69 --- /dev/null +++ b/src/main/resources/assets/computercraft/recipes/wireless_modem.json @@ -0,0 +1,13 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "###", + "#E#", + "###" + ], + "key": { + "#": { "item": "minecraft:stone", "data": 0 }, + "E": { "item": "minecraft:ender_pearl" } + }, + "result": { "item": "computercraft:peripheral", "data": 1 } +}