diff --git a/.gitignore b/.gitignore index 22222fc39..1317d0286 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,28 @@ # eclipse -eclipse -bin -*.launch -.settings -.metadata -.classpath -.project +/eclipse +/bin +/*.launch +/.settings +/.metadata +/.classpath +/.project # idea -out -*.ipr -*.iws -*.iml -.idea +/out +/*.ipr +/*.iws +/*.iml +/.idea # gradle -build -.gradle +/build +/.gradle + +# vscode +/.vscode # other -run +/run # CurseForge configuration /curseforge.properties diff --git a/src/main/java/com/hbm/blocks/generic/BlockScaffoldDynamic.java b/src/main/java/com/hbm/blocks/generic/BlockScaffoldDynamic.java index 814ddb5b1..62a42594c 100644 --- a/src/main/java/com/hbm/blocks/generic/BlockScaffoldDynamic.java +++ b/src/main/java/com/hbm/blocks/generic/BlockScaffoldDynamic.java @@ -167,7 +167,8 @@ public class BlockScaffoldDynamic extends BlockContainer implements IToolable, I } } - public static class TileEntityScaffoldDynamic extends TileEntity { + // Full class name needed because otherwise there's some conflict with the static import * from this class + public static class TileEntityScaffoldDynamic extends net.minecraft.tileentity.TileEntity { public int composite; public int prevComposite; diff --git a/src/main/java/com/hbm/crafting/handlers/ContainerUpgradeCraftingHandler.java b/src/main/java/com/hbm/crafting/handlers/ContainerUpgradeCraftingHandler.java new file mode 100644 index 000000000..22949d25f --- /dev/null +++ b/src/main/java/com/hbm/crafting/handlers/ContainerUpgradeCraftingHandler.java @@ -0,0 +1,58 @@ +package com.hbm.crafting.handlers; + +import java.util.ArrayList; + +import com.hbm.blocks.generic.BlockStorageCrate; +import com.hbm.blocks.machine.BlockMassStorage; + +import net.minecraft.block.Block; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +/** + * Handles upgrading storage crates and mass storage blocks, preserving their contents. + * + * Note: this assumes the input and the output items store their inventory in the same format + * in the NBT + */ +public class ContainerUpgradeCraftingHandler extends ShapedOreRecipe { + + public ContainerUpgradeCraftingHandler(ItemStack result, Object... items){ + super(result, items); + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) { + + ItemStack source = getFirstContainer(inventoryCrafting); + ItemStack result = super.getCraftingResult(inventoryCrafting); + + result.setTagCompound(source.getTagCompound()); + + return result; + } + + private static ItemStack getFirstContainer(InventoryCrafting inventoryCrafting) { + for (int i = 0; i < 9; ++i) { + ItemStack itemstack = inventoryCrafting.getStackInRowAndColumn(i % 3, i / 3); + if (itemstack == null) + continue; + + Block block = Block.getBlockFromItem(itemstack.getItem()); + if (block == null) + continue; + + if (block instanceof BlockStorageCrate || block instanceof BlockMassStorage) + return itemstack; + } + return null; + } + +} diff --git a/src/main/java/com/hbm/main/CraftingManager.java b/src/main/java/com/hbm/main/CraftingManager.java index b4dc3b87f..cce77298b 100644 --- a/src/main/java/com/hbm/main/CraftingManager.java +++ b/src/main/java/com/hbm/main/CraftingManager.java @@ -79,6 +79,7 @@ public class CraftingManager { RecipeSorter.register("hbm:cargo", CargoShellCraftingHandler.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless"); RecipeSorter.register("hbm:scraps", ScrapsCraftingHandler.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless"); RecipeSorter.register("hbm:mku", MKUCraftingHandler.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped before:minecraft:shapeless"); + RecipeSorter.register("hbm:containerupgrade", ContainerUpgradeCraftingHandler.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped before:minecraft:shapeless"); } public static void AddCraftingRec() { @@ -282,13 +283,17 @@ public class CraftingManager { addRecipeAuto(new ItemStack(ModBlocks.crate_template, 1), new Object[] { "IPI", "P P", "IPI", 'I', IRON.ingot(), 'P', Items.paper }); addRecipeAuto(new ItemStack(ModBlocks.crate_iron, 1), new Object[] { "PPP", "I I", "III", 'P', IRON.plate(), 'I', IRON.ingot() }); addRecipeAuto(new ItemStack(ModBlocks.crate_steel, 1), new Object[] { "PPP", "I I", "III", 'P', STEEL.plate(), 'I', STEEL.ingot() }); - addRecipeAuto(new ItemStack(ModBlocks.crate_desh, 1), new Object[] { " D ", "DSD", " D ", 'D', ModItems.plate_desh, 'S', ModBlocks.crate_steel }); - addRecipeAuto(new ItemStack(ModBlocks.crate_tungsten, 1), new Object[] { "BPB", "PCP", "BPB", 'B', W.block(), 'P', CU.plateCast(), 'C', ModBlocks.crate_steel }); - addRecipeAuto(new ItemStack(ModBlocks.safe, 1), new Object[] { "LAL", "ACA", "LAL", 'L', PB.plate(), 'A', ALLOY.plate(), 'C', ModBlocks.crate_steel }); + + GameRegistry.addRecipe(new ContainerUpgradeCraftingHandler(new ItemStack(ModBlocks.crate_desh, 1), new Object[] { " D ", "DSD", " D ", 'D', ModItems.plate_desh, 'S', ModBlocks.crate_steel })); + GameRegistry.addRecipe(new ContainerUpgradeCraftingHandler(new ItemStack(ModBlocks.crate_tungsten, 1), new Object[] { "BPB", "PCP", "BPB", 'B', W.block(), 'P', CU.plateCast(), 'C', ModBlocks.crate_steel })); + // Note: voids the last few slots when placed, because a safe's inventory is smaller than a crate's one + GameRegistry.addRecipe(new ContainerUpgradeCraftingHandler(new ItemStack(ModBlocks.safe, 1), new Object[] { "LAL", "ACA", "LAL", 'L', PB.plate(), 'A', ALLOY.plate(), 'C', ModBlocks.crate_steel })); + // Note: doesn't preserve storage because a crate's contents are different items, but a mass storage's is just one addRecipeAuto(new ItemStack(ModBlocks.mass_storage, 1, 0), new Object[] { "ICI", "CLC", "ICI", 'I', TI.ingot(), 'C', ModBlocks.crate_steel, 'L', DictFrame.fromOne(ModItems.circuit, EnumCircuitType.VACUUM_TUBE) }); - addRecipeAuto(new ItemStack(ModBlocks.mass_storage, 1, 1), new Object[] { "PCP", "PMP", "PPP", 'P', DESH.ingot(), 'C', DictFrame.fromOne(ModItems.circuit, EnumCircuitType.CHIP), 'M', new ItemStack(ModBlocks.mass_storage, 1, 0) }); - addRecipeAuto(new ItemStack(ModBlocks.mass_storage, 1, 2), new Object[] { "PCP", "PMP", "PPP", 'P', ANY_RESISTANTALLOY.ingot(), 'C', DictFrame.fromOne(ModItems.circuit, EnumCircuitType.ADVANCED), 'M', new ItemStack(ModBlocks.mass_storage, 1, 1) }); - addRecipeAuto(new ItemStack(ModBlocks.mass_storage, 1, 3), new Object[] { "PPP", "PIP", "PPP", 'P', KEY_PLANKS, 'I', IRON.plate() }); + GameRegistry.addRecipe(new ContainerUpgradeCraftingHandler(new ItemStack(ModBlocks.mass_storage, 1, 1), new Object[] { "PCP", "PMP", "PPP", 'P', DESH.ingot(), 'C', DictFrame.fromOne(ModItems.circuit, EnumCircuitType.CHIP), 'M', new ItemStack(ModBlocks.mass_storage, 1, 0) })); + GameRegistry.addRecipe(new ContainerUpgradeCraftingHandler(new ItemStack(ModBlocks.mass_storage, 1, 2), new Object[] { "PCP", "PMP", "PPP", 'P', ANY_RESISTANTALLOY.ingot(), 'C', DictFrame.fromOne(ModItems.circuit, EnumCircuitType.ADVANCED), 'M', new ItemStack(ModBlocks.mass_storage, 1, 1) })); + GameRegistry.addRecipe(new ContainerUpgradeCraftingHandler(new ItemStack(ModBlocks.mass_storage, 1, 3), new Object[] { "PPP", "PIP", "PPP", 'P', KEY_PLANKS, 'I', IRON.plate() })); + addRecipeAuto(new ItemStack(ModBlocks.machine_autocrafter, 1), new Object[] { "SCS", "MWM", "SCS", 'S', STEEL.plate(), 'C', DictFrame.fromOne(ModItems.circuit, EnumCircuitType.VACUUM_TUBE), 'M', ModItems.motor, 'W', Blocks.crafting_table }); addRecipeAuto(new ItemStack(ModBlocks.machine_funnel, 1), new Object[] { "S S", "SRS", " S ", 'S', STEEL.ingot(), 'R', REDSTONE.dust() }); addRecipeAuto(new ItemStack(ModBlocks.machine_waste_drum, 1), new Object[] { "LRL", "BRB", "LRL", 'L', PB.ingot(), 'B', Blocks.iron_bars, 'R', ModItems.rod_quad_empty });