Scrapboxes work in dispensers (w/ config option)

This commit is contained in:
TheDoctorSoda 2016-03-08 00:15:34 -08:00
parent c5302f8d6b
commit 02dd024e83
5 changed files with 150 additions and 112 deletions

View file

@ -4,8 +4,7 @@ import java.io.File;
import org.apache.commons.lang3.time.StopWatch; import org.apache.commons.lang3.time.StopWatch;
import net.minecraft.init.Items; import net.minecraft.block.BlockDispenser;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
@ -24,7 +23,6 @@ import reborncore.common.packets.AddDiscriminatorEvent;
import reborncore.common.util.LogHelper; import reborncore.common.util.LogHelper;
import reborncore.common.util.VersionChecker; import reborncore.common.util.VersionChecker;
import techreborn.achievement.TRAchievements; import techreborn.achievement.TRAchievements;
import techreborn.api.ScrapboxList;
import techreborn.api.TechRebornAPI; import techreborn.api.TechRebornAPI;
import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.recipeConfig.RecipeConfigManager; import techreborn.api.recipe.recipeConfig.RecipeConfigManager;
@ -33,19 +31,13 @@ import techreborn.command.TechRebornDevCommand;
import techreborn.compat.CompatManager; import techreborn.compat.CompatManager;
import techreborn.compat.ICompatModule; import techreborn.compat.ICompatModule;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
import techreborn.dispenser.BehaviorDispenseScrapbox;
import techreborn.events.OreUnifier; import techreborn.events.OreUnifier;
import techreborn.events.TRTickHandler; import techreborn.events.TRTickHandler;
import techreborn.init.ModBlocks; import techreborn.init.*;
import techreborn.init.ModFluids;
import techreborn.init.ModItems;
import techreborn.init.ModLoot;
import techreborn.init.ModParts;
import techreborn.init.ModRecipes;
import techreborn.init.RecipeCompact;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
import techreborn.packets.PacketAesu; import techreborn.packets.PacketAesu;
import techreborn.packets.PacketIdsu; import techreborn.packets.PacketIdsu;
import techreborn.power.PowerTickEvent;
import techreborn.proxies.CommonProxy; import techreborn.proxies.CommonProxy;
import techreborn.tiles.idsu.IDSUManager; import techreborn.tiles.idsu.IDSUManager;
import techreborn.world.TROreGen; import techreborn.world.TROreGen;
@ -75,8 +67,7 @@ public class Core {
FMLCommonHandler.instance().bus().register(this); FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
String path = event.getSuggestedConfigurationFile().getAbsolutePath() String path = event.getSuggestedConfigurationFile().getAbsolutePath().replace(ModInfo.MOD_ID, "TechReborn");
.replace(ModInfo.MOD_ID, "TechReborn");
config = ConfigTechReborn.initialize(new File(path)); config = ConfigTechReborn.initialize(new File(path));
configDir = event.getModConfigurationDirectory(); configDir = event.getModConfigurationDirectory();
@ -136,6 +127,9 @@ public class Core {
MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler()); MinecraftForge.EVENT_BUS.register(new MultiblockServerTickHandler());
MinecraftForge.EVENT_BUS.register(new TRTickHandler()); MinecraftForge.EVENT_BUS.register(new TRTickHandler());
MinecraftForge.EVENT_BUS.register(new OreUnifier()); MinecraftForge.EVENT_BUS.register(new OreUnifier());
if (config.scrapboxDispenser) {
BlockDispenser.dispenseBehaviorRegistry.putObject(ModItems.scrapBox, new BehaviorDispenseScrapbox());
}
logHelper.info("Initialization Complete"); logHelper.info("Initialization Complete");
} }
@ -168,7 +162,6 @@ public class Core {
} }
} }
@SubscribeEvent @SubscribeEvent
public void addDiscriminator(AddDiscriminatorEvent event) { public void addDiscriminator(AddDiscriminatorEvent event) {
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketAesu.class); event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketAesu.class);

View file

@ -56,6 +56,8 @@ import techreborn.compat.jei.scrapbox.ScrapboxRecipeCategory;
import techreborn.compat.jei.scrapbox.ScrapboxRecipeHandler; import techreborn.compat.jei.scrapbox.ScrapboxRecipeHandler;
import techreborn.compat.jei.vacuumFreezer.VacuumFreezerRecipeCategory; import techreborn.compat.jei.vacuumFreezer.VacuumFreezerRecipeCategory;
import techreborn.compat.jei.vacuumFreezer.VacuumFreezerRecipeHandler; import techreborn.compat.jei.vacuumFreezer.VacuumFreezerRecipeHandler;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModItems;
import techreborn.items.ItemParts; import techreborn.items.ItemParts;
@mezz.jei.api.JEIPlugin @mezz.jei.api.JEIPlugin
@ -120,6 +122,11 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
} }
registry.addDescription(ItemParts.getPartByName("rubberSap"), StatCollector.translateToLocal("techreborn.desc.rubberSap")); registry.addDescription(ItemParts.getPartByName("rubberSap"), StatCollector.translateToLocal("techreborn.desc.rubberSap"));
if(!ConfigTechReborn.scrapboxDispenser){
registry.addDescription(new ItemStack(ModItems.scrapBox), StatCollector.translateToLocal("techreborn.desc.scrapBoxNoDispenser"));
} else {
registry.addDescription(new ItemStack(ModItems.scrapBox), StatCollector.translateToLocal("techreborn.desc.scrapBox"));
}
registry.addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER, VanillaRecipeCategoryUid.FUEL); registry.addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER, VanillaRecipeCategoryUid.FUEL);
registry.addRecipeClickArea(GuiAlloySmelter.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER); registry.addRecipeClickArea(GuiAlloySmelter.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER);

View file

@ -84,6 +84,8 @@ public class ConfigTechReborn {
public static boolean UninsulatedElectocutionParticle; public static boolean UninsulatedElectocutionParticle;
public static boolean UninsulatedElectocutionDamage; public static boolean UninsulatedElectocutionDamage;
public static boolean scrapboxDispenser;
// Power // Power
public static int ThermalGenertaorOutput; public static int ThermalGenertaorOutput;
public static int CentrifugeInputTick; public static int CentrifugeInputTick;
@ -692,6 +694,10 @@ public class ConfigTechReborn {
.get(CATEGORY_WORLD, "Uninsulated Electocution Particle", true, "Spawn particles on contact with uninsulated cables") .get(CATEGORY_WORLD, "Uninsulated Electocution Particle", true, "Spawn particles on contact with uninsulated cables")
.getBoolean(true); .getBoolean(true);
scrapboxDispenser = config
.get(CATEGORY_WORLD, "Scrapboxes in Dispenser", true, "Allow scrapbox to be opened via dispenser")
.getBoolean(true);
ExpensiveWatermill = config ExpensiveWatermill = config
.get(CATEGORY_CRAFTING, "Expensive Watermill", true, "Allow TechReborn to change the Watermill recipe") .get(CATEGORY_CRAFTING, "Expensive Watermill", true, "Allow TechReborn to change the Watermill recipe")
.getBoolean(true); .getBoolean(true);

View file

@ -0,0 +1,30 @@
package techreborn.dispenser;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.dispenser.IPosition;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import techreborn.api.ScrapboxList;
import techreborn.init.ModItems;
public class BehaviorDispenseScrapbox extends BehaviorDefaultDispenseItem {
@Override
protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
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;
stack.splitStack(1);
EnumFacing enumfacing = BlockDispenser.getFacing(source.getBlockMetadata());
IPosition iposition = BlockDispenser.getDispensePosition(source);
doDispense(source.getWorld(), out, 6, enumfacing, iposition);
return stack;
}
}

View file

@ -976,6 +976,8 @@ techreborn.jei.recipe.processing.time.1=Time: %s ticks
techreborn.jei.recipe.processing.time.2=(%s seconds) techreborn.jei.recipe.processing.time.2=(%s seconds)
jei.techreborn.scrapbox.name=Opening Scrapboxes jei.techreborn.scrapbox.name=Opening Scrapboxes
techreborn.desc.rubberSap=In order to get sap, you need to find a rubber tree or obtain a rubber tree sapling and proceed to grow it. Once you have obtained a rubber tree, search around for little yellowish spots on the tree. If you don't see any, just wait a bit and eventually these yellow "sap" spots. To harvest the sap, use a treetap and use it on the log. techreborn.desc.rubberSap=In order to get sap, you need to find a rubber tree or obtain a rubber tree sapling and proceed to grow it. Once you have obtained a rubber tree, search around for little yellowish spots on the tree. If you don't see any, just wait a bit and eventually these yellow "sap" spots. To harvest the sap, use a treetap and use it on the log.
techreborn.desc.scrapBox=Scrapboxes can be opened by either a simple use in hand, or by dispensers. That's right, just throw your scrapboxes into dispensers and give them a redstone signal, and boom! Random item!
techreborn.desc.scrapBoxNoDispenser=Scrapboxes can be opened by a simple use in hand!
techreborn.jei.category.alloy.furnace=Alloy Furnace techreborn.jei.category.alloy.furnace=Alloy Furnace