From 4fc45221a2b9408b995c54a563f7cfc949d41fd9 Mon Sep 17 00:00:00 2001 From: drcrazy Date: Wed, 17 Jan 2018 13:53:25 +0300 Subject: [PATCH] Removed scrapboxlist usage. Closes #1407 --- .../compat/crafttweaker/CTScrapbox.java | 4 --- .../dispenser/BehaviorDispenseScrapbox.java | 15 ++++++----- .../init/recipes/ScrapboxRecipes.java | 11 +++----- .../java/techreborn/items/ItemScrapBox.java | 27 +++++++++---------- .../techreborn/tiles/TileScrapboxinator.java | 14 +++++++--- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/main/java/techreborn/compat/crafttweaker/CTScrapbox.java b/src/main/java/techreborn/compat/crafttweaker/CTScrapbox.java index 689a74603..4f2663350 100644 --- a/src/main/java/techreborn/compat/crafttweaker/CTScrapbox.java +++ b/src/main/java/techreborn/compat/crafttweaker/CTScrapbox.java @@ -37,7 +37,6 @@ import reborncore.api.recipe.RecipeHandler; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; import techreborn.api.Reference; -import techreborn.api.ScrapboxList; import techreborn.api.recipe.BaseRecipe; import techreborn.api.recipe.ScrapboxRecipe; import techreborn.compat.crafttweaker.CTGeneric.Remove; @@ -50,13 +49,11 @@ public class CTScrapbox { @ZenMethod public static void addScrapboxDrop(IIngredient input) { - ScrapboxList.stacks.add(CraftTweakerMC.getItemStack(input)); RecipeHandler.addRecipe(new ScrapboxRecipe(CraftTweakerMC.getItemStack(input))); } @ZenMethod public static void removeRecipe(IItemStack output) { - ScrapboxList.stacks.remove(CraftTweakerCompat.toStack(output)); CraftTweakerAPI.apply(new Remove(CraftTweakerCompat.toStack(output), getMachineName())); } @@ -79,7 +76,6 @@ public class CTScrapbox { @Override public void apply() { - ScrapboxList.stacks.clear(); for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(name)) { removedRecipes.add((BaseRecipe) recipeType); RecipeHandler.recipeList.remove(recipeType); diff --git a/src/main/java/techreborn/dispenser/BehaviorDispenseScrapbox.java b/src/main/java/techreborn/dispenser/BehaviorDispenseScrapbox.java index 11992fcee..02b5cfa35 100644 --- a/src/main/java/techreborn/dispenser/BehaviorDispenseScrapbox.java +++ b/src/main/java/techreborn/dispenser/BehaviorDispenseScrapbox.java @@ -24,6 +24,9 @@ package techreborn.dispenser; +import java.util.List; +import java.util.Random; + import net.minecraft.block.BlockDispenser; import net.minecraft.dispenser.BehaviorDefaultDispenseItem; import net.minecraft.dispenser.IBlockSource; @@ -32,9 +35,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntityDispenser; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import reborncore.api.recipe.IBaseRecipeType; +import reborncore.api.recipe.RecipeHandler; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; -import techreborn.api.ScrapboxList; +import techreborn.api.Reference; import techreborn.lib.ModInfo; @RebornRegistry(modID = ModInfo.MOD_ID) @@ -46,11 +51,9 @@ public class BehaviorDispenseScrapbox extends BehaviorDefaultDispenseItem { @Override protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) { if (dispenseScrapboxes) { - int random = source.getWorld().rand.nextInt(ScrapboxList.stacks.size()); - ItemStack out = ScrapboxList.stacks.get(random).copy(); -/* float xOffset = source.getWorld().rand.nextFloat() * 0.8F + 0.1F; - float yOffset = source.getWorld().rand.nextFloat() * 0.8F + 0.1F; - float zOffset = source.getWorld().rand.nextFloat() * 0.8F + 0.1F;*/ + List scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.scrapboxRecipe); + int random = new Random().nextInt(scrapboxRecipeList.size()); + ItemStack out = scrapboxRecipeList.get(random).getOutput(0); stack.splitStack(1); TileEntityDispenser tile = source.getBlockTileEntity(); diff --git a/src/main/java/techreborn/init/recipes/ScrapboxRecipes.java b/src/main/java/techreborn/init/recipes/ScrapboxRecipes.java index 751987ea4..90ee183a0 100644 --- a/src/main/java/techreborn/init/recipes/ScrapboxRecipes.java +++ b/src/main/java/techreborn/init/recipes/ScrapboxRecipes.java @@ -30,7 +30,6 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import reborncore.api.recipe.RecipeHandler; -import techreborn.api.ScrapboxList; import techreborn.api.recipe.ScrapboxRecipe; import techreborn.init.ModBlocks; import techreborn.init.ModItems; @@ -215,17 +214,13 @@ public class ScrapboxRecipes extends RecipeMethods { registerDyable(Blocks.STAINED_GLASS); registerDyable(Blocks.STAINED_GLASS_PANE); registerDyable(Blocks.STAINED_HARDENED_CLAY); - - for (int i = 0; i < ScrapboxList.stacks.size(); i++) { - RecipeHandler.addRecipe(new ScrapboxRecipe(ScrapboxList.stacks.get(i))); - } } - static void register(ItemStack stack) { - if(stack == null || stack.isEmpty()){ + static void register(ItemStack output) { + if(output == null || output.isEmpty()){ return; } - ScrapboxList.stacks.add(stack); + RecipeHandler.addRecipe(new ScrapboxRecipe(output)); } static void registerDyable(Item item) { diff --git a/src/main/java/techreborn/items/ItemScrapBox.java b/src/main/java/techreborn/items/ItemScrapBox.java index e1c0a0750..2ba4a7e77 100644 --- a/src/main/java/techreborn/items/ItemScrapBox.java +++ b/src/main/java/techreborn/items/ItemScrapBox.java @@ -24,14 +24,18 @@ package techreborn.items; -import net.minecraft.entity.item.EntityItem; +import java.util.List; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; -import techreborn.api.ScrapboxList; +import reborncore.api.recipe.IBaseRecipeType; +import reborncore.api.recipe.RecipeHandler; +import reborncore.common.util.WorldUtils; +import techreborn.api.Reference; import techreborn.client.TechRebornCreativeTabMisc; public class ItemScrapBox extends ItemTR { @@ -42,20 +46,13 @@ public class ItemScrapBox extends ItemTR { } @Override - public ActionResult onItemRightClick(World world, EntityPlayer player, - EnumHand hand) { - ItemStack stack = player.getHeldItem(hand); + public ActionResult onItemRightClick(World world, EntityPlayer player, EnumHand hand) { + ItemStack stack = player.getHeldItemMainhand(); if (!world.isRemote) { - int random = world.rand.nextInt(ScrapboxList.stacks.size()); - ItemStack out = ScrapboxList.stacks.get(random).copy(); - float xOffset = world.rand.nextFloat() * 0.8F + 0.1F; - float yOffset = world.rand.nextFloat() * 0.8F + 0.1F; - float zOffset = world.rand.nextFloat() * 0.8F + 0.1F; - EntityItem entityitem = new EntityItem(world, player.getPosition().getX() + xOffset, - player.getPosition().getY() + yOffset, player.getPosition().getZ() + zOffset, out); - - entityitem.setPickupDelay(20); - world.spawnEntity(entityitem); + List scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.scrapboxRecipe); + int random = world.rand.nextInt(scrapboxRecipeList.size()); + ItemStack out = scrapboxRecipeList.get(random).getOutput(0); + WorldUtils.dropItem(out, world, player.getPosition()); stack.shrink(1); } return new ActionResult<>(EnumActionResult.SUCCESS, stack); diff --git a/src/main/java/techreborn/tiles/TileScrapboxinator.java b/src/main/java/techreborn/tiles/TileScrapboxinator.java index 595bbbc08..341dd67da 100644 --- a/src/main/java/techreborn/tiles/TileScrapboxinator.java +++ b/src/main/java/techreborn/tiles/TileScrapboxinator.java @@ -24,18 +24,22 @@ package techreborn.tiles; +import java.util.List; + import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import reborncore.api.IToolDrop; +import reborncore.api.recipe.IBaseRecipeType; +import reborncore.api.recipe.RecipeHandler; import reborncore.api.tile.IInventoryProvider; import reborncore.common.blocks.BlockMachineBase; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.util.Inventory; -import techreborn.api.ScrapboxList; +import techreborn.api.Reference; import techreborn.client.container.IContainerProvider; import techreborn.client.container.builder.BuiltContainer; import techreborn.client.container.builder.ContainerBuilder; @@ -107,8 +111,9 @@ public class TileScrapboxinator extends TilePowerAcceptor public void recycleItems() { if (this.canOpen() && !this.world.isRemote) { - int random = world.rand.nextInt(ScrapboxList.stacks.size()); - ItemStack out = ScrapboxList.stacks.get(random).copy(); + List scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.scrapboxRecipe); + int random = world.rand.nextInt(scrapboxRecipeList.size()); + ItemStack out = scrapboxRecipeList.get(random).getOutput(0); if (this.getStackInSlot(this.output).isEmpty()) { this.useEnergy(cost); this.setInventorySlotContents(this.output, out); @@ -125,8 +130,9 @@ public class TileScrapboxinator extends TilePowerAcceptor } public boolean canOpen() { + List scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.scrapboxRecipe); return !this.getStackInSlot(this.input1).isEmpty() && this.getStackInSlot(this.output).isEmpty() - && ScrapboxList.stacks.size() > 0; + && scrapboxRecipeList.size() > 0; } public boolean isBurning() {