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;
@ -53,125 +45,126 @@ import techreborn.world.TreeGenerator;
@Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = ModInfo.MOD_DEPENDENCUIES, guiFactory = ModInfo.GUI_FACTORY_CLASS, acceptedMinecraftVersions = "[1.8.8,1.8.9]") @Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = ModInfo.MOD_DEPENDENCUIES, guiFactory = ModInfo.GUI_FACTORY_CLASS, acceptedMinecraftVersions = "[1.8.8,1.8.9]")
public class Core { public class Core {
public static ConfigTechReborn config; public static ConfigTechReborn config;
@SidedProxy(clientSide = ModInfo.CLIENT_PROXY_CLASS, serverSide = ModInfo.SERVER_PROXY_CLASS) @SidedProxy(clientSide = ModInfo.CLIENT_PROXY_CLASS, serverSide = ModInfo.SERVER_PROXY_CLASS)
public static CommonProxy proxy; public static CommonProxy proxy;
@Mod.Instance @Mod.Instance
public static Core INSTANCE; public static Core INSTANCE;
public VersionChecker versionChecker; public VersionChecker versionChecker;
public static LogHelper logHelper = new LogHelper(new ModInfo()); public static LogHelper logHelper = new LogHelper(new ModInfo());
private static RecipeCompact recipeCompact; private static RecipeCompact recipeCompact;
private static File configDir; private static File configDir;
@Mod.EventHandler @Mod.EventHandler
public void preinit(FMLPreInitializationEvent event) { public void preinit(FMLPreInitializationEvent event) {
event.getModMetadata().version = ModInfo.MOD_VERSION; event.getModMetadata().version = ModInfo.MOD_VERSION;
INSTANCE = this; INSTANCE = this;
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();
recipeCompact = new RecipeCompact(); recipeCompact = new RecipeCompact();
TechRebornAPI.recipeCompact = recipeCompact; TechRebornAPI.recipeCompact = recipeCompact;
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) { for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.preInit(event); compatModule.preInit(event);
} }
RecipeConfigManager.load(event.getModConfigurationDirectory()); RecipeConfigManager.load(event.getModConfigurationDirectory());
versionChecker = new VersionChecker("TechReborn", new ModInfo()); versionChecker = new VersionChecker("TechReborn", new ModInfo());
versionChecker.checkVersionThreaded(); versionChecker.checkVersionThreaded();
logHelper.info("PreInitialization Complete"); logHelper.info("PreInitialization Complete");
} }
@Mod.EventHandler @Mod.EventHandler
public void init(FMLInitializationEvent event) throws IllegalAccessException, InstantiationException { public void init(FMLInitializationEvent event) throws IllegalAccessException, InstantiationException {
// Register ModBlocks // Register ModBlocks
ModBlocks.init(); ModBlocks.init();
// Register Fluids // Register Fluids
ModFluids.init(); ModFluids.init();
// Register ModItems // Register ModItems
ModItems.init(); ModItems.init();
// Registers Chest Loot // Registers Chest Loot
ModLoot.init(); ModLoot.init();
//Multiparts // Multiparts
ModParts.init(); ModParts.init();
// Compat // Compat
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) { for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.init(event); compatModule.init(event);
} }
// Recipes // Recipes
StopWatch watch = new StopWatch(); StopWatch watch = new StopWatch();
watch.start(); watch.start();
ModRecipes.init(); ModRecipes.init();
logHelper.all(watch + " : main recipes"); logHelper.all(watch + " : main recipes");
watch.stop(); watch.stop();
//Client only init, needs to be done before parts system // Client only init, needs to be done before parts system
proxy.init(); proxy.init();
// WorldGen // WorldGen
GameRegistry.registerWorldGenerator(new TROreGen(), 0); GameRegistry.registerWorldGenerator(new TROreGen(), 0);
GameRegistry.registerWorldGenerator(new TreeGenerator(), 0); GameRegistry.registerWorldGenerator(new TreeGenerator(), 0);
// DungeonLoot.init(); // DungeonLoot.init();
// Register Gui Handler // Register Gui Handler
NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler()); NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
// Achievements // Achievements
TRAchievements.init(); TRAchievements.init();
// Multiblock events // Multiblock events
MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler()); MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler());
// IDSU manager // IDSU manager
IDSUManager.INSTANCE = new IDSUManager(); IDSUManager.INSTANCE = new IDSUManager();
MinecraftForge.EVENT_BUS.register(IDSUManager.INSTANCE); MinecraftForge.EVENT_BUS.register(IDSUManager.INSTANCE);
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());
logHelper.info("Initialization Complete"); if (config.scrapboxDispenser) {
} BlockDispenser.dispenseBehaviorRegistry.putObject(ModItems.scrapBox, new BehaviorDispenseScrapbox());
}
logHelper.info("Initialization Complete");
}
@Mod.EventHandler @Mod.EventHandler
public void postinit(FMLPostInitializationEvent event) throws Exception { public void postinit(FMLPostInitializationEvent event) throws Exception {
// Has to be done here as Buildcraft registers their recipes late // Has to be done here as Buildcraft registers their recipes late
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) { for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.postInit(event); compatModule.postInit(event);
} }
logHelper.info(RecipeHandler.recipeList.size() + " recipes loaded"); logHelper.info(RecipeHandler.recipeList.size() + " recipes loaded");
// RecipeHandler.scanForDupeRecipes(); // RecipeHandler.scanForDupeRecipes();
//RecipeConfigManager.save(); // RecipeConfigManager.save();
recipeCompact.saveMissingItems(configDir); recipeCompact.saveMissingItems(configDir);
} }
@Mod.EventHandler @Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event) { public void serverStarting(FMLServerStartingEvent event) {
event.registerServerCommand(new TechRebornDevCommand()); event.registerServerCommand(new TechRebornDevCommand());
for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) { for (ICompatModule compatModule : CompatManager.INSTANCE.compatModules) {
compatModule.serverStarting(event); compatModule.serverStarting(event);
} }
} }
@SubscribeEvent @SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent cfgChange) { public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent cfgChange) {
if (cfgChange.modID.equals("TechReborn")) { if (cfgChange.modID.equals("TechReborn")) {
ConfigTechReborn.Configs(); ConfigTechReborn.Configs();
} }
} }
@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); event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketIdsu.class);
event.getPacketHandler().addDiscriminator(event.getPacketHandler().nextDiscriminator, PacketIdsu.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