From 0f74091da59befd856490dd7aac88ff3b8a10cf2 Mon Sep 17 00:00:00 2001 From: kindlich Date: Sat, 19 Oct 2019 23:49:58 +0200 Subject: [PATCH] Started with 1.10 and 1.11.2 --- .../main/java/minetweaker/MineTweakerAPI.java | 14 +- .../api/compat/DummyJEIRecipeRegistry.java | 64 ++ .../api/compat/IJEIRecipeRegistry.java | 35 + MineTweaker3-MC1102-Main/build.gradle | 39 +- .../java/com/blamejared/ctgui/MTRecipe.java | 11 +- .../com/blamejared/ctgui/api/CheckButton.java | 32 +- .../ctgui/api/CheckButtonRecipe.java | 37 +- .../blamejared/ctgui/api/ContainerBase.java | 56 +- .../com/blamejared/ctgui/api/GuiBase.java | 153 ++- .../com/blamejared/ctgui/api/GuiRegistry.java | 10 +- .../java/com/blamejared/ctgui/api/Slider.java | 1 + .../com/blamejared/ctgui/api/SlotRecipe.java | 63 +- .../blamejared/ctgui/client/GuiHandler.java | 7 +- .../ctgui/client/GuiHandlerVanilla.java | 10 +- .../ctgui/client/InventoryFake.java | 13 +- .../blamejared/ctgui/client/gui/GuiMenu.java | 191 ++-- .../craftingtable/ContainerCraftingTable.java | 26 +- .../gui/craftingtable/GuiCraftingTable.java | 66 +- .../client/gui/furnace/ContainerFurnace.java | 22 +- .../ctgui/client/gui/furnace/GuiFurnace.java | 7 +- .../ctgui/commands/CommandCTGUI.java | 14 +- .../blamejared/ctgui/proxy/ClientProxy.java | 2 +- .../api/minecraft/MineTweakerMC.java | 954 +++++++++--------- .../minetweaker/mc1102/FMLEventHandler.java | 49 +- .../minetweaker/mc1102/ForgeEventHandler.java | 73 +- .../minetweaker/mc1102/GuiCannotRemodify.java | 18 +- .../mc1102/MCPlatformFunctions.java | 17 +- .../minetweaker/mc1102/MineTweakerMod.java | 188 ++-- .../mc1102/MineTweakerRegistry.java | 11 +- .../actions/SetBlockHardnessAction.java | 63 +- .../mc1102/actions/SetStackSizeAction.java | 24 +- .../actions/SetStackmaxDamageAction.java | 42 +- .../mc1102/actions/SetTranslationAction.java | 90 +- .../mc1102/block/MCBlockDefinition.java | 17 +- .../minetweaker/mc1102/block/MCItemBlock.java | 35 +- .../mc1102/block/MCSpecificBlock.java | 39 +- .../mc1102/block/MCWorldBlock.java | 45 +- .../mc1102/brackets/EntityBracketHandler.java | 77 ++ .../mc1102/brackets/ItemBracketHandler.java | 97 +- .../mc1102/brackets/LiquidBracketHandler.java | 48 +- .../mc1102/brackets/OreBracketHandler.java | 48 +- .../mc1102/brewing/MCBrewingManager.java | 88 +- .../mc1102/chat/MCChatMessage.java | 20 +- .../minetweaker/mc1102/client/MCClient.java | 15 +- .../minetweaker/mc1102/data/NBTConverter.java | 62 +- .../minetweaker/mc1102/data/NBTUpdater.java | 34 +- .../mc1102/entity/MCEntityDefinition.java | 66 +- .../formatting/FormattedMarkupString.java | 19 +- .../mc1102/formatting/FormattedString.java | 19 +- .../formatting/FormattedStringJoin.java | 29 +- .../mc1102/formatting/IMCFormattedString.java | 9 +- .../mc1102/formatting/MCFormatter.java | 55 +- .../mc1102/furnace/FuelTweaker.java | 80 +- .../mc1102/furnace/MCFurnaceManager.java | 206 ++-- .../mc1102/furnace/SetFuelPattern.java | 15 +- .../java/minetweaker/mc1102/game/MCGame.java | 140 +-- .../mc1102/item/MCItemDefinition.java | 44 +- .../minetweaker/mc1102/item/MCItemStack.java | 335 +++--- .../mc1102/liquid/MCLiquidDefinition.java | 166 ++- .../mc1102/liquid/MCLiquidStack.java | 79 +- .../minetweaker/mc1102/logger/MCLogger.java | 80 ++ .../minetweaker/mc1102/mods/MCLoadedMods.java | 28 +- .../java/minetweaker/mc1102/mods/MCMod.java | 19 +- .../MineTweakerCopyClipboardHandler.java | 28 +- .../MineTweakerCopyClipboardPacket.java | 19 +- .../MineTweakerLoadScriptsHandler.java | 30 +- .../network/MineTweakerLoadScriptsPacket.java | 29 +- .../MineTweakerOpenBrowserHandler.java | 43 +- .../network/MineTweakerOpenBrowserPacket.java | 19 +- .../minetweaker/mc1102/oredict/MCOreDict.java | 25 +- .../mc1102/oredict/MCOreDictEntry.java | 71 +- .../mc1102/player/CommandBlockPlayer.java | 73 +- .../minetweaker/mc1102/player/MCPlayer.java | 88 +- .../minetweaker/mc1102/player/RconPlayer.java | 73 +- .../mc1102/recipes/MCCraftingInventory.java | 113 +-- .../mc1102/recipes/MCRecipeManager.java | 145 +-- .../mc1102/recipes/RecipeConverter.java | 106 +- .../mc1102/recipes/ShapedRecipeAdvanced.java | 28 +- .../mc1102/recipes/ShapedRecipeBasic.java | 26 +- .../mc1102/recipes/ShapedRecipeOre.java | 26 +- .../recipes/ShapelessRecipeAdvanced.java | 28 +- .../mc1102/recipes/ShapelessRecipeBasic.java | 27 +- .../mc1102/recipes/ShapelessRecipeOre.java | 22 +- .../minetweaker/mc1102/server/MCServer.java | 58 +- .../mc1102/server/ServerPlayer.java | 81 +- .../mc1102/util/MineTweakerHacks.java | 179 ++-- .../mc1102/util/MineTweakerObfuscation.java | 14 +- .../mc1102/util/MineTweakerPlatformUtils.java | 25 +- .../mc1102/vanilla/MCSeedRegistry.java | 78 +- .../minetweaker/mc1102/vanilla/MCVanilla.java | 19 +- .../minetweaker/mc1102/world/MCBiome.java | 13 +- .../minetweaker/mc1102/world/MCDimension.java | 19 +- .../src/main/resources/mcmod.info | 30 +- MineTweaker3-MC1102-Mod-IC2/build.gradle | 27 +- .../mods/ic2/IC2BracketHandler.java | 152 ++- .../mods/ic2/IC2ExplosionWhitelist.java | 263 ++--- .../minetweaker/mods/ic2/IC2RecipeInput.java | 95 +- .../mods/ic2/MachineAddRecipeAction.java | 33 +- .../java/minetweaker/mods/ic2/crops/Crop.java | 105 +- .../mods/ic2/crops/CropsConfig.java | 438 ++++---- .../mods/ic2/crops/GrowthRequirements.java | 248 ++--- .../mods/ic2/crops/SyntheticCrop.java | 77 +- .../mods/ic2/expand/IngredientExpansion.java | 58 +- .../mods/ic2/expand/ItemExpansion.java | 178 ++-- .../mods/ic2/machines/BlastFurnace.java | 94 +- .../mods/ic2/machines/BlockCutter.java | 99 +- .../minetweaker/mods/ic2/machines/Canner.java | 412 ++++---- .../mods/ic2/machines/Compressor.java | 98 +- .../mods/ic2/machines/Extractor.java | 99 +- .../mods/ic2/machines/FluidHeatGenerator.java | 138 ++- .../mods/ic2/machines/Macerator.java | 93 +- .../mods/ic2/machines/MatterAmplifier.java | 31 +- .../mods/ic2/machines/MetalFormer.java | 187 ++-- .../mods/ic2/machines/OreWasher.java | 51 +- .../mods/ic2/machines/Recycler.java | 116 +-- .../mods/ic2/machines/ScrapBox.java | 133 ++- .../mods/ic2/machines/SemiFluidGenerator.java | 138 ++- .../mods/ic2/machines/ThermalCentrifuge.java | 125 ++- MineTweaker3-MC1102-Mod-JEI/build.gradle | 35 +- .../main/java/minetweaker/mods/jei/JEI.java | 119 +-- .../minetweaker/mods/jei/JEIAddonPlugin.java | 38 +- .../java/minetweaker/mods/jei/JEIMod.java | 15 + .../mods/jei/JEIRecipeRegistry.java | 132 +++ build.gradle | 48 +- configuration.gradle | 10 + 125 files changed, 4845 insertions(+), 4991 deletions(-) create mode 100644 MineTweaker3-API/src/main/java/minetweaker/api/compat/DummyJEIRecipeRegistry.java create mode 100644 MineTweaker3-API/src/main/java/minetweaker/api/compat/IJEIRecipeRegistry.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/EntityBracketHandler.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/logger/MCLogger.java create mode 100644 MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIMod.java create mode 100644 MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIRecipeRegistry.java diff --git a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerAPI.java b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerAPI.java index 7111abd..9b00c55 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/MineTweakerAPI.java +++ b/MineTweaker3-API/src/main/java/minetweaker/MineTweakerAPI.java @@ -3,6 +3,7 @@ package minetweaker; import minetweaker.annotations.BracketHandler; import minetweaker.annotations.ModOnly; import minetweaker.api.client.IClient; +import minetweaker.api.compat.*; import minetweaker.api.event.IEventManager; import minetweaker.api.formatting.IFormatter; import minetweaker.api.game.IGame; @@ -68,8 +69,9 @@ public class MineTweakerAPI { "Red", "Black" }; - - static { + private static IJEIRecipeRegistry ijeiRecipeRegistry = new DummyJEIRecipeRegistry(); + + static { registerClassRegistry(ClassRegistry.class, "MT-API"); registerGlobalSymbol("logger", getJavaStaticGetterSymbol(MineTweakerAPI.class, "getLogger")); @@ -436,4 +438,12 @@ public class MineTweakerAPI { public static IJavaMethod getJavaMethod(Class cls, String name, Class... arguments) { return JavaMethod.get(GlobalRegistry.getTypeRegistry(), cls, name, arguments); } + + public static IJEIRecipeRegistry getIjeiRecipeRegistry() { + return ijeiRecipeRegistry; + } + + public static void setIjeiRecipeRegistry(IJEIRecipeRegistry ijeiRecipeRegistry) { + MineTweakerAPI.ijeiRecipeRegistry = ijeiRecipeRegistry; + } } diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/compat/DummyJEIRecipeRegistry.java b/MineTweaker3-API/src/main/java/minetweaker/api/compat/DummyJEIRecipeRegistry.java new file mode 100644 index 0000000..14d7add --- /dev/null +++ b/MineTweaker3-API/src/main/java/minetweaker/api/compat/DummyJEIRecipeRegistry.java @@ -0,0 +1,64 @@ +package minetweaker.api.compat; + +import minetweaker.api.item.IIngredient; + +import java.util.*; + +public class DummyJEIRecipeRegistry implements IJEIRecipeRegistry { + + @Override + public void addRecipe(Object object) { + } + + @Override + public void addRecipe(Object object, String category) { + + } + + @Override + public void removeRecipe(Object object) { + } + + @Override + public void removeRecipe(Object output, String category) { + + } + + @Override + public void addFurnace(List inputs, Object output) { + } + + @Override + public void removeFurnace(Object object) { + } + + @Override + public void addFuel(Collection input, int burnTime) { + + } + + @Override + public void removeFuel(Object object) { + + } + + @Override + public void reloadItemList() { + + } + + @Override + public void removeItem(Object stack) { + + } + + @Override + public void addItem(Object stack) { + + } + + @Override + public void invalidateTooltips(IIngredient ingredient) { + + } +} diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/compat/IJEIRecipeRegistry.java b/MineTweaker3-API/src/main/java/minetweaker/api/compat/IJEIRecipeRegistry.java new file mode 100644 index 0000000..a26ae63 --- /dev/null +++ b/MineTweaker3-API/src/main/java/minetweaker/api/compat/IJEIRecipeRegistry.java @@ -0,0 +1,35 @@ +package minetweaker.api.compat; + +import minetweaker.api.item.IIngredient; + +import java.util.*; + +public interface IJEIRecipeRegistry { + + void addRecipe(Object object); + + void addRecipe(Object object, String category); + + void removeRecipe(Object output); + + void removeRecipe(Object output, String category); + + + void addFurnace(List inputs, Object output); + + void removeFurnace(Object output); + + void addFuel(Collection input, int burnTime); + + void removeFuel(Object object); + + void invalidateTooltips(IIngredient ingredient); + + //To update the items in 1.10.2 + void reloadItemList(); + + //To update the items in 1.11.2 both below are used + void removeItem(Object stack); + + void addItem(Object stack); +} diff --git a/MineTweaker3-MC1102-Main/build.gradle b/MineTweaker3-MC1102-Main/build.gradle index bb37001..5d2c405 100644 --- a/MineTweaker3-MC1102-Main/build.gradle +++ b/MineTweaker3-MC1102-Main/build.gradle @@ -1,8 +1,5 @@ import minetweaker.tasks.RegisterZenClassesTask; - - - buildscript { repositories { jcenter() @@ -27,38 +24,38 @@ archivesBaseName = project.projectDir.name minecraft { version = forgeVersion1102 runDir = "eclipse" - mappings = "snapshot_20160518" + mappings = "stable_29" } dependencies { - compile project(':ZenScript') - compile project(':MineTweaker3-API') + compile project(':ZenScript') + compile project(':MineTweaker3-API') } task makeRegistry(type: RegisterZenClassesTask) { - inputDir = file('build/classes/main') - outputDir = file('build/classes/main') - className = 'minetweaker.mc1102.MineTweakerRegistry' + inputDir = file('build/classes/main') + outputDir = file('build/classes/main') + className = 'minetweaker.mc1102.MineTweakerRegistry' } tasks.jar.dependsOn(makeRegistry) processResources -{ + { - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' - expand 'version':project.version, 'mcversion':project.minecraft.version - } - - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} + expand 'version': project.version, 'mcversion': project.minecraft.version + } + + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } + } uploadArchives { repositories { diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java index 5e177b1..c938cfd 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java @@ -4,13 +4,10 @@ import com.blamejared.ctgui.api.GuiRegistry; import com.blamejared.ctgui.client.GuiHandlerVanilla; import com.blamejared.ctgui.commands.CommandCTGUI; import com.blamejared.ctgui.proxy.CommonProxy; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.common.*; +import net.minecraftforge.fml.common.event.*; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import static com.blamejared.ctgui.reference.Reference.*; @@ -25,7 +22,7 @@ public class MTRecipe { @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { - List idrange = new ArrayList(); + List idrange = new ArrayList<>(); idrange.add(1); idrange.add(2); GuiRegistry.registerGui(idrange, new GuiHandlerVanilla()); diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java index bc6fcc5..466e492 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java @@ -3,16 +3,12 @@ package com.blamejared.ctgui.api; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.GlStateManager; -import net.minecraftforge.fml.client.config.GuiCheckBox; -import net.minecraftforge.fml.client.config.GuiUtils; +import net.minecraftforge.fml.client.config.*; import org.lwjgl.opengl.GL11; import java.awt.*; import java.util.List; -/** - * Created by Jared. - */ public class CheckButton extends GuiCheckBox { protected GuiBase parent; @@ -34,19 +30,19 @@ public class CheckButton extends GuiCheckBox { this.backgroundSize = backgroundSize; } - public void setIncompatible(List incompatible) { - this.incompatible = incompatible; - } - public List getIncompatible() { return incompatible; } + public void setIncompatible(List incompatible) { + this.incompatible = incompatible; + } + /** * Draws this button to the screen. */ public void drawButton(Minecraft mc, int mouseX, int mouseY) { - if (this.visible) { + if(this.visible) { this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + getButtonWidth() && mouseY < this.yPosition + this.height; GlStateManager.enableAlpha(); GL11.glColor4d(1, 1, 1, 0); @@ -56,13 +52,13 @@ public class CheckButton extends GuiCheckBox { this.mouseDragged(mc, mouseX, mouseY); int color = 14737632; - if (packedFGColour != 0) { + if(packedFGColour != 0) { color = packedFGColour; - } else if (!this.enabled) { + } else if(!this.enabled) { color = 10526880; } - if (this.isChecked()) { + if(this.isChecked()) { this.drawGradientRect(this.xPosition + 2, this.yPosition + 2, this.xPosition + 11 - 2, this.yPosition + height - 2, Color.cyan.darker().getRGB(), Color.cyan.darker().getRGB()); } @@ -72,7 +68,7 @@ public class CheckButton extends GuiCheckBox { @Override public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { - if (this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { + if(this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { setIsChecked(!isChecked()); return true; } @@ -82,15 +78,15 @@ public class CheckButton extends GuiCheckBox { public void setIsChecked(boolean isChecked) { super.setIsChecked(isChecked); - if (isChecked()) { - for (GuiButton but : incompatible) { + if(isChecked()) { + for(GuiButton but : incompatible) { but.enabled = false; - if (but instanceof CheckButton) { + if(but instanceof CheckButton) { ((CheckButton) but).setIsChecked(false); } } } else { - for (GuiButton but : incompatible) { + for(GuiButton but : incompatible) { but.enabled = true; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java index f0cb500..18af6e1 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java @@ -8,9 +8,6 @@ import net.minecraft.item.ItemStack; import java.util.ArrayList; -/** - * Created by Jared. - */ public class CheckButtonRecipe extends CheckButton { private String propertyKey; @@ -23,21 +20,21 @@ public class CheckButtonRecipe extends CheckButton { @Override public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { - if (this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { + if(this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { setIsChecked(!isChecked()); parent.selectedSlot.getPropertyMap().put(getPropertyKey(), isChecked()); - if (isChecked()) { - for (Slider slider : parent.getMenu().getSliders(this)) { - if (parent.isBlock(parent.selectedSlot.getStack())) { + if(isChecked()) { + for(Slider slider : parent.getMenu().getSliders(this)) { + if(GuiBase.isBlock(parent.selectedSlot.getStack())) { Block b = Block.getBlockFromItem(parent.selectedSlot.getStack().getItem()); - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); b.getSubBlocks(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); slider.maxValue = list.size() - 1; slider.updateSlider(); } else { - if (parent.selectedSlot.getStack().getItem().getHasSubtypes()) { - ArrayList list = new ArrayList(); + if(parent.selectedSlot.getStack().getItem().getHasSubtypes()) { + ArrayList list = new ArrayList<>(); parent.selectedSlot.getStack().getItem().getSubItems(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); slider.maxValue = list.size() - 1; @@ -51,7 +48,7 @@ public class CheckButtonRecipe extends CheckButton { parent.getButtonList().add(slider); } } else { - for (Slider slider : parent.getMenu().getSliders(this)) { + for(Slider slider : parent.getMenu().getSliders(this)) { parent.getButtonList().remove(slider); } } @@ -63,18 +60,18 @@ public class CheckButtonRecipe extends CheckButton { public void setIsChecked(boolean isChecked) { super.setIsChecked(isChecked); - if (isChecked()) { - for (Slider slider : parent.getMenu().getSliders(this)) { - if (GuiBase.isBlock(parent.selectedSlot.getStack())) { + if(isChecked()) { + for(Slider slider : parent.getMenu().getSliders(this)) { + if(GuiBase.isBlock(parent.selectedSlot.getStack())) { Block b = Block.getBlockFromItem(parent.selectedSlot.getStack().getItem()); - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); b.getSubBlocks(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); slider.maxValue = list.size() - 1; slider.updateSlider(); } else { - if (parent.selectedSlot.getStack().getItem().getHasSubtypes()) { - ArrayList list = new ArrayList(); + if(parent.selectedSlot.getStack().getItem().getHasSubtypes()) { + ArrayList list = new ArrayList<>(); parent.selectedSlot.getStack().getItem().getSubItems(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); slider.maxValue = list.size() - 1; @@ -87,14 +84,14 @@ public class CheckButtonRecipe extends CheckButton { } parent.getButtonList().add(slider); } - for (GuiButton but : incompatible) { + for(GuiButton but : incompatible) { but.enabled = false; } } else { - for (Slider slider : parent.getMenu().getSliders(this)) { + for(Slider slider : parent.getMenu().getSliders(this)) { parent.getButtonList().remove(slider); } - for (GuiButton but : incompatible) { + for(GuiButton but : incompatible) { but.enabled = true; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java index e6c2a96..c903eda 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java @@ -1,21 +1,15 @@ package com.blamejared.ctgui.api; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ClickType; -import net.minecraft.inventory.Container; +import net.minecraft.entity.player.*; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; import javax.annotation.Nullable; -import java.util.LinkedList; -import java.util.List; +import java.util.*; -/** - * Created by Jared on 5/29/2016. - */ public class ContainerBase extends Container { - protected List recipeSlots = new LinkedList(); + protected List recipeSlots = new LinkedList<>(); @Override public boolean canInteractWith(EntityPlayer player) { @@ -28,45 +22,51 @@ public class ContainerBase extends Container { public ItemStack slotClick(int i, int mousebtn, ClickType clickTypeIn, EntityPlayer player) { ItemStack stack = null; - if (i >= 0 && getSlot(i) != null && getSlot(i) instanceof SlotRecipe) // Fake slots + if(i >= 0 && getSlot(i) != null && getSlot(i) instanceof SlotRecipe) // Fake slots { - if (mousebtn == 2) { + if(mousebtn == 2) { getSlot(i).putStack(null); - } else if (mousebtn == 0) { + } else if(mousebtn == 0) { InventoryPlayer playerInv = player.inventory; getSlot(i).onSlotChanged(); ItemStack stackSlot = getSlot(i).getStack(); ItemStack stackHeld = playerInv.getItemStack(); - if (stackSlot != null) stack = stackSlot.copy(); + if(stackSlot != null) + stack = stackSlot.copy(); - if (stackHeld != null) { + if(stackHeld != null) { ItemStack newStack = stackHeld.copy(); - if (!(getSlot(i) instanceof SlotRecipeOutput)) newStack.stackSize = 1; + if(!(getSlot(i) instanceof SlotRecipeOutput)) + newStack.stackSize = 1; getSlot(i).putStack(newStack); - } else getSlot(i).putStack(null); - } else if (mousebtn == 1) { + } else + getSlot(i).putStack(null); + } else if(mousebtn == 1) { InventoryPlayer playerInv = player.inventory; getSlot(i).onSlotChanged(); ItemStack stackSlot = getSlot(i).getStack(); ItemStack stackHeld = playerInv.getItemStack(); - if (stackSlot != null) stack = stackSlot.copy(); + if(stackSlot != null) + stack = stackSlot.copy(); - if (stackHeld != null) { + if(stackHeld != null) { stackHeld = stackHeld.copy(); - if (stackSlot != null && stackHeld.isItemEqual(stackSlot) && (i == 0 || i == 0)) { + if(stackSlot != null && stackHeld.isItemEqual(stackSlot) && (i == 0 || i == 0)) { int max = stackSlot.getMaxStackSize(); - if (++stackSlot.stackSize > max) stackSlot.stackSize = max; + if(++stackSlot.stackSize > max) + stackSlot.stackSize = max; getSlot(i).putStack(stackSlot); } else { stackHeld.stackSize = 1; getSlot(i).putStack(stackHeld); } } else { - if (stackSlot != null) { + if(stackSlot != null) { stackSlot.stackSize--; - if (stackSlot.stackSize == 0) getSlot(i).putStack(null); + if(stackSlot.stackSize == 0) + getSlot(i).putStack(null); } } } @@ -85,4 +85,12 @@ public class ContainerBase extends Container { public List getRecipeSlots() { return recipeSlots; } + + @Override + protected Slot addSlotToContainer(Slot slotIn) { + if(slotIn instanceof SlotRecipe) { + getRecipeSlots().add((SlotRecipe) slotIn); + } + return super.addSlotToContainer(slotIn); + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java index 13e11c0..9549d0f 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java @@ -3,8 +3,7 @@ package com.blamejared.ctgui.api; import com.blamejared.ctgui.client.gui.GuiMenu; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.*; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.item.ItemStack; @@ -14,19 +13,17 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.io.*; -import java.util.LinkedList; +import java.util.*; import java.util.List; public abstract class GuiBase extends GuiContainer { - protected ContainerBase container; public SlotRecipe selectedSlot; - protected GuiMenu menu = new GuiMenu(); public GuiTextField editingField; - public GuiButton add; public GuiButton remove; - + protected ContainerBase container; + protected GuiMenu menu = new GuiMenu(); private boolean shouldOpenMenu; public GuiBase(ContainerBase container, int xSize, int ySize, boolean shouldOpenMenu) { @@ -37,12 +34,17 @@ public abstract class GuiBase extends GuiContainer { this.shouldOpenMenu = shouldOpenMenu; } + public static boolean isBlock(ItemStack stack) { + ResourceLocation name = Block.REGISTRY.getNameForObject(Block.getBlockFromItem(stack.getItem())); + return !(name != null && name.toString().equals("minecraft:air")) && Block.REGISTRY.containsKey(name); + } + @Override public void initGui() { super.initGui(); buttonList.clear(); - if (shouldOpenMenu) - menu.open(this, guiLeft - 102, guiTop+2); + if(shouldOpenMenu) + menu.open(this, guiLeft - 102, guiTop + 2); editingField = new GuiTextField(2906, fontRendererObj, guiLeft - 104, guiTop - 26, xSize + 102, 20); editingField.setMaxStringLength(Integer.MAX_VALUE); editingField.setEnabled(true); @@ -62,15 +64,15 @@ public abstract class GuiBase extends GuiContainer { @Override public void updateScreen() { super.updateScreen(); - if (selectedSlot != null) { - if (!selectedSlot.getHasStack()) { + if(selectedSlot != null) { + if(!selectedSlot.getHasStack()) { selectedSlot = null; editingField.setText(""); - if (shouldOpenMenu) { + if(shouldOpenMenu) { menu.setState(false); menu.toggle(false); - for (Pair but : menu.getButtons()) { - for (Slider slider : but.getValue()) { + for(Pair but : menu.getButtons()) { + for(Slider slider : but.getValue()) { slider.setValue(0); slider.maxValue = 0; slider.updateSlider(); @@ -83,40 +85,33 @@ public abstract class GuiBase extends GuiContainer { } } else { editingField.setText(""); - if (shouldOpenMenu) { + if(shouldOpenMenu) { menu.setState(false); menu.toggle(false); - for (Pair but : menu.getButtons()) { - for (Slider slider : but.getValue()) { + for(Pair but : menu.getButtons()) { + for(Slider slider : but.getValue()) { slider.setValue(0); slider.maxValue = 0; slider.updateSlider(); buttonList.remove(slider); } } - ; } } editingField.updateCursorCounter(); final boolean[] canCreate = {true}; - for (SlotRecipe slot : container.getRecipeSlots()) { - if (slot instanceof SlotRecipeOutput) { - if (!slot.getHasStack()) { - canCreate[0] = false; - } - } - } - if (!canCreate[0]) { + container.getRecipeSlots().stream().filter(slot -> slot instanceof SlotRecipeOutput).filter(slot -> !slot.getHasStack()).forEach(slot -> canCreate[0] = false); + if(!canCreate[0]) { add.enabled = false; remove.enabled = false; } else { add.enabled = true; remove.enabled = true; } - if (shouldOpenMenu) { - if (selectedSlot != null) { - if (selectedSlot.getHasStack() && !selectedSlot.getStack().hasTagCompound()) { + if(shouldOpenMenu) { + if(selectedSlot != null) { + if(selectedSlot.getHasStack() && !selectedSlot.getStack().hasTagCompound()) { menu.nbt.getLeft().enabled = false; } } @@ -126,21 +121,21 @@ public abstract class GuiBase extends GuiContainer { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { final boolean[] clickedSlot = new boolean[]{false}; - for (SlotRecipe slot : container.getRecipeSlots()) { - Rectangle rectangle = new Rectangle(guiLeft + slot.xDisplayPosition, guiTop + slot.yDisplayPosition, 18, 18); - if (rectangle.contains(mouseX, mouseY)) { - switch (mouseButton) { + for(SlotRecipe slot : container.getRecipeSlots()) { + Rectangle rectangle = new Rectangle(guiLeft + slot.xPos, guiTop + slot.yPos, 18, 18); + if(rectangle.contains(mouseX, mouseY)) { + switch(mouseButton) { case 0: break; case 1: - if (slot.getHasStack()) { + if(slot.getHasStack()) { clickedSlot[0] = true; selectedSlot = slot; editingField.setText(slot.getItemString()); - if (shouldOpenMenu) { + if(shouldOpenMenu) { menu.toggle(true); - for (Pair but : menu.getButtons()) { - for (Slider slider : but.getValue()) { + for(Pair but : menu.getButtons()) { + for(Slider slider : but.getValue()) { buttonList.remove(slider); } } @@ -151,23 +146,23 @@ public abstract class GuiBase extends GuiContainer { case 2: clickedSlot[0] = true; selectedSlot = null; - if (shouldOpenMenu) { + if(shouldOpenMenu) { menu.toggle(false); - for (Pair but : menu.getButtons()) { - for (Slider slider : but.getValue()) { + for(Pair but : menu.getButtons()) { + for(Slider slider : but.getValue()) { slider.updateSlider(); buttonList.remove(slider); } } } - if (editingField != null) + if(editingField != null) editingField.setText(""); break; } } } - if (!clickedSlot[0]) { + if(!clickedSlot[0]) { super.mouseClicked(mouseX, mouseY, mouseButton); } } @@ -176,97 +171,87 @@ public abstract class GuiBase extends GuiContainer { public abstract String getOutputRemove(); - protected void actionPerformed(GuiButton btn) { - if (btn.equals(add)) { + if(btn.equals(add)) { File scriptFile = new File(new File("scripts"), "/recipes.zs"); - if (!scriptFile.exists()) { + if(!scriptFile.exists()) { generateFile(scriptFile); } try { - List lines = new LinkedList(); + List lines = new LinkedList<>(); BufferedReader reader = new BufferedReader(new FileReader(scriptFile)); - String line = ""; - while ((line = reader.readLine()) != null) { + String line; + while((line = reader.readLine()) != null) { lines.add(line); } - if (lines.isEmpty()) { + if(lines.isEmpty()) { generateFile(scriptFile); - while ((line = reader.readLine()) != null) { + while((line = reader.readLine()) != null) { lines.add(line); } } reader.close(); PrintWriter writer = new PrintWriter(new FileWriter(scriptFile)); - for (int i = 0; i < lines.size(); i++) { + for(int i = 0; i < lines.size(); i++) { String beforeLine = ""; - if (i > 0) + if(i > 0) beforeLine = lines.get(i - 1); String lined = lines.get(i); - if (beforeLine.trim().equals("//#Remove")) { - } - if (beforeLine.trim().equals("//#Add")) { + if(beforeLine.trim().equals("//#Add")) { writer.println(getOutputAdd()); } - if (!lined.isEmpty()) { + if(!lined.isEmpty()) { writer.println(lined); } } writer.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); } } - if (btn.equals(remove)) { + if(btn.equals(remove)) { File scriptFile = new File(new File("scripts"), "/recipes.zs"); - if (!scriptFile.exists()) { + if(!scriptFile.exists()) { generateFile(scriptFile); } try { - List lines = new LinkedList(); + List lines = new LinkedList<>(); BufferedReader reader = new BufferedReader(new FileReader(scriptFile)); - String line = ""; - while ((line = reader.readLine()) != null) { + String line; + while((line = reader.readLine()) != null) { lines.add(line); } - if (lines.isEmpty()) { + if(lines.isEmpty()) { generateFile(scriptFile); - while ((line = reader.readLine()) != null) { + while((line = reader.readLine()) != null) { lines.add(line); } } reader.close(); PrintWriter writer = new PrintWriter(new FileWriter(scriptFile)); - for (int i = 0; i < lines.size(); i++) { + for(int i = 0; i < lines.size(); i++) { String beforeLine = ""; - if (i > 0) + if(i > 0) beforeLine = lines.get(i - 1); String lined = lines.get(i); - if (beforeLine.trim().equals("//#Remove")) { + if(beforeLine.trim().equals("//#Remove")) { writer.println(getOutputRemove()); } - if (beforeLine.trim().equals("//#Add")) { - } - if (!lined.isEmpty()) { + if(!lined.isEmpty()) { writer.println(lined); } } writer.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); } } } - public abstract ResourceLocation getTexture(); protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { @@ -275,9 +260,9 @@ public abstract class GuiBase extends GuiContainer { Minecraft.getMinecraft().renderEngine.bindTexture(getTexture()); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); GlStateManager.popAttrib(); - if (selectedSlot != null) { + if(selectedSlot != null) { GlStateManager.colorMask(true, true, true, false); - this.drawGradientRect(guiLeft + selectedSlot.xDisplayPosition, guiTop + selectedSlot.yDisplayPosition, guiLeft + selectedSlot.xDisplayPosition + 16, guiTop + selectedSlot.yDisplayPosition + 16, Color.cyan.darker().getRGB(), Color.cyan.darker().getRGB()); + this.drawGradientRect(guiLeft + selectedSlot.xPos, guiTop + selectedSlot.yPos, guiLeft + selectedSlot.xPos + 16, guiTop + selectedSlot.yPos + 16, Color.cyan.darker().getRGB(), Color.cyan.darker().getRGB()); GlStateManager.colorMask(true, true, true, true); } } @@ -286,7 +271,6 @@ public abstract class GuiBase extends GuiContainer { return this.buttonList; } - public int getGuiLeft() { return guiLeft; } @@ -295,7 +279,6 @@ public abstract class GuiBase extends GuiContainer { return guiTop; } - public int getXSize() { return xSize; } @@ -304,14 +287,6 @@ public abstract class GuiBase extends GuiContainer { return ySize; } - public static boolean isBlock(ItemStack stack) { - ResourceLocation name = Block.REGISTRY.getNameForObject(Block.getBlockFromItem(stack.getItem())); - if (name != null && name.toString().equals("minecraft:air")) { - return false; - } - return Block.REGISTRY.containsKey(name); - } - public GuiMenu getMenu() { return menu; } @@ -330,7 +305,7 @@ public abstract class GuiBase extends GuiContainer { writer.println(); writer.println("//File End"); writer.close(); - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java index c8bfe83..bf360d3 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java @@ -2,24 +2,22 @@ package com.blamejared.ctgui.api; import net.minecraftforge.fml.common.network.IGuiHandler; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Created by Jared. */ public class GuiRegistry { - public static Map, IGuiHandler> guiMap = new HashMap, IGuiHandler>(); + public static Map, IGuiHandler> guiMap = new HashMap<>(); public static void registerGui(List idRange, IGuiHandler handler) { getGuiMap().put(idRange, handler); } public static IGuiHandler getHandlerForID(int id) { - for (Map.Entry, IGuiHandler> entry : getGuiMap().entrySet()) { - if (entry.getKey().contains(id)) { + for(Map.Entry, IGuiHandler> entry : getGuiMap().entrySet()) { + if(entry.getKey().contains(id)) { return entry.getValue(); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java index 4536151..05e98b9 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java @@ -6,6 +6,7 @@ import net.minecraftforge.fml.client.config.GuiSlider; * Created by Jared. */ public class Slider extends GuiSlider { + private String propertyKey; public Slider(String propertyKey, int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr) { diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java index 7292878..840f785 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java @@ -2,15 +2,12 @@ package com.blamejared.ctgui.api; import minetweaker.mc1102.data.NBTConverter; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.inventory.*; +import net.minecraft.item.*; import net.minecraftforge.oredict.OreDictionary; import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * Created by Jared. @@ -18,8 +15,8 @@ import java.util.Map; public class SlotRecipe extends Slot { //key is the operation, value is the values, for more than 1 value, seperate using ยง - private Map propertyMap = new HashMap(); - private Map properties = new HashMap(); + private Map propertyMap = new HashMap<>(); + private Map properties = new HashMap<>(); public SlotRecipe(IInventory inventoryIn, int index, int xPosition, int yPosition) { @@ -47,35 +44,43 @@ public class SlotRecipe extends Slot { boolean matchAny = getPropertyFromMap("matchNotEmpty"); boolean metaWildcard = getPropertyFromMap("anyMetadata"); boolean oreDict = getPropertyFromMap("oreDictionary"); - if (getStack() == null) return "null"; + if(getStack() == null) + return "null"; String stackName = Item.REGISTRY.getNameForObject(getStack().getItem()).toString(); StringBuilder builder = new StringBuilder("<"); - if (oreDict) { + if(oreDict) { int[] ids = OreDictionary.getOreIDs(getStack()); - if (ids.length != 0) { + if(ids.length != 0) { stackName = "ore:" + OreDictionary.getOreName(ids[0]); - } else oreDict = false; + } else + oreDict = false; } - if (matchAny) { + if(matchAny) { stackName = "*"; } builder.append(stackName); - if (!oreDict && !matchAny && (metaWildcard || getStack().getItemDamage() != 0)) + if(!oreDict && !matchAny && (metaWildcard || getStack().getItemDamage() != 0)) builder.append(':').append(metaWildcard || getStack().getItemDamage() == OreDictionary.WILDCARD_VALUE ? "*" : getStack().getItemDamage()); builder.append('>'); - if (getStack().stackSize > 1) builder.append(" * ").append(getStack().stackSize); - if (getPropertyFromMap("anyDamage")) builder.append(".anyDamage()"); - if (getPropertyFromMap("onlyDamage")) builder.append(".onlyDamaged()"); - if (getPropertyFromMap("gted")) - builder.append(".onlyDamageAtLeast(").append("" + getProperty("gted")).append(')'); - if (getPropertyFromMap("ltd")) - builder.append(".onlyDamageAtMost(").append("" + getProperty("ltd")).append(')'); - if (getPropertyFromMap("betweenDamage")) - builder.append(".onlyDamageBetween(").append("" + getProperty("betweenDamageX")).append(", ").append("" + getProperty("betweenDamageY")).append(')'); - if (getPropertyFromMap("reuse")) builder.append(".reuse()"); - if (getPropertyFromMap("noreturn")) builder.append(".noReturn()"); - if (getPropertyFromMap("nbt")) { - if (this instanceof SlotRecipeOutput) + if(getStack().stackSize > 1) + builder.append(" * ").append(getStack().stackSize); + if(getPropertyFromMap("anyDamage")) + builder.append(".anyDamage()"); + if(getPropertyFromMap("onlyDamage")) + builder.append(".onlyDamaged()"); + if(getPropertyFromMap("gted")) + builder.append(".onlyDamageAtLeast(").append("").append(getProperty("gted")).append(')'); + if(getPropertyFromMap("ltd")) + builder.append(".onlyDamageAtMost(").append("").append(getProperty("ltd")).append(')'); + if(getPropertyFromMap("betweenDamage")) { + builder.append(".onlyDamageBetween(").append("").append(getProperty("betweenDamageX")).append(", ").append("").append(getProperty("betweenDamageY")).append(')'); + } + if(getPropertyFromMap("reuse")) + builder.append(".reuse()"); + if(getPropertyFromMap("noreturn")) + builder.append(".noReturn()"); + if(getPropertyFromMap("nbt")) { + if(this instanceof SlotRecipeOutput) builder.append(String.format(".withTag(%s)", NBTConverter.from(getStack().getTagCompound(), false).toString())); else builder.append(String.format(".onlyWithTag(%s)", NBTConverter.from(getStack().getTagCompound(), false).toString())); @@ -84,14 +89,14 @@ public class SlotRecipe extends Slot { } boolean getPropertyFromMap(String key) { - if (propertyMap.containsKey(key)) { + if(propertyMap.containsKey(key)) { return propertyMap.get(key); } return false; } int getProperty(String key) { - if (properties.containsKey(key)) { + if(properties.containsKey(key)) { return properties.get(key); } return 0; diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java index 6d56a86..ae3c18e 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java @@ -4,8 +4,7 @@ import com.blamejared.ctgui.MTRecipe; import com.blamejared.ctgui.api.GuiRegistry; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; -import net.minecraftforge.fml.common.network.IGuiHandler; -import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.common.network.*; /** * Created by Jared. @@ -18,7 +17,7 @@ public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - if (GuiRegistry.getHandlerForID(ID) == null) { + if(GuiRegistry.getHandlerForID(ID) == null) { return null; } return GuiRegistry.getHandlerForID(ID).getServerGuiElement(ID, player, world, x, y, z); @@ -26,7 +25,7 @@ public class GuiHandler implements IGuiHandler { @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - if (GuiRegistry.getHandlerForID(ID) == null) { + if(GuiRegistry.getHandlerForID(ID) == null) { return null; } return GuiRegistry.getHandlerForID(ID).getClientGuiElement(ID, player, world, x, y, z); diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java index d483691..b131d92 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java @@ -1,9 +1,7 @@ package com.blamejared.ctgui.client; -import com.blamejared.ctgui.client.gui.craftingtable.ContainerCraftingTable; -import com.blamejared.ctgui.client.gui.craftingtable.GuiCraftingTable; -import com.blamejared.ctgui.client.gui.furnace.ContainerFurnace; -import com.blamejared.ctgui.client.gui.furnace.GuiFurnace; +import com.blamejared.ctgui.client.gui.craftingtable.*; +import com.blamejared.ctgui.client.gui.furnace.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; @@ -15,7 +13,7 @@ public class GuiHandlerVanilla implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - switch (ID) { + switch(ID) { case 1: return new ContainerCraftingTable(player.inventory); case 2: @@ -26,7 +24,7 @@ public class GuiHandlerVanilla implements IGuiHandler { @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { - switch (ID) { + switch(ID) { case 1: return new GuiCraftingTable(new ContainerCraftingTable(player.inventory)); case 2: diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java index 1445000..4c44c4f 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java @@ -1,8 +1,7 @@ package com.blamejared.ctgui.client; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ItemStackHelper; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; import net.minecraft.util.text.ITextComponent; @@ -35,8 +34,7 @@ public class InventoryFake implements IInventory { @Nullable @Override public ItemStack decrStackSize(int index, int count) { - ItemStack itemstack = ItemStackHelper.getAndSplit(items, index, count); - return itemstack; + return ItemStackHelper.getAndSplit(items, index, count); } @Nullable @@ -59,11 +57,12 @@ public class InventoryFake implements IInventory { public void markDirty() { } - + @Override - public boolean isUseableByPlayer(EntityPlayer player) { + public boolean isUsableByPlayer(EntityPlayer player) { return true; } + @Override public void openInventory(EntityPlayer player) { @@ -97,7 +96,7 @@ public class InventoryFake implements IInventory { @Override public void clear() { - for (int i = 0; i < this.items.length; ++i) { + for(int i = 0; i < this.items.length; ++i) { this.items[i] = null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java index bcfc0ac..65c341a 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java @@ -1,134 +1,111 @@ package com.blamejared.ctgui.client.gui; -import com.blamejared.ctgui.api.CheckButtonRecipe; -import com.blamejared.ctgui.api.GuiBase; -import com.blamejared.ctgui.api.Slider; -import net.minecraft.client.gui.GuiButton; -import net.minecraftforge.fml.client.config.GuiSlider; -import org.apache.commons.lang3.tuple.MutablePair; -import org.apache.commons.lang3.tuple.Pair; +import com.blamejared.ctgui.api.*; +import net.minecraftforge.fml.relauncher.*; +import org.apache.commons.lang3.tuple.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; -/** - * Created by Jared. - */ +@SideOnly(Side.CLIENT) public class GuiMenu { - private GuiBase parent; - private int x; - private int y; - private List> buttons = new ArrayList>(); + // public Pair matchNotEmpty; public Pair useOreDict; public Pair matchAnyMetadata; public Pair anyDamage; public Pair onlyDamage; - // public Pair damage; public Pair greaterThanEqualDamage; public Pair lessThanDamage; public Pair betweenDamage; - public Pair nbt; - // public Pair transformDamage; -// public Pair transformReplace; + // public Pair transformReplace; public Pair reuse; public Pair noReturn; -// public Pair giveBack; - - + private GuiBase parent; + private int x; + private int y; + private List> buttons = new ArrayList<>(); + // public Pair giveBack; + + public GuiMenu() { } - + public void open(final GuiBase parent, int x, int y) { this.parent = parent; this.x = x; this.y = y; int buttonCount = 0; -// matchNotEmpty = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Match Not Empty", false, "matchNotEmpty"), new Slider[]{}); - useOreDict = new MutablePair(new CheckButtonRecipe(parent, 1, x, y + (15 * buttonCount++), "Ore Dictionary", false, "oreDictionary"), new Slider[]{}); - matchAnyMetadata = new MutablePair(new CheckButtonRecipe(parent, 2, x, y + (15 * buttonCount++), "Any Metadata", false, "anyMetadata"), new Slider[]{}); - anyDamage = new MutablePair(new CheckButtonRecipe(parent, 3, x, y + (15 * buttonCount++), "Any Damage", false, "anyDamage"), new Slider[]{}); - onlyDamage = new MutablePair(new CheckButtonRecipe(parent, 4, x, y + (15 * buttonCount++), "Only Damage", false, "onlyDamage"), new Slider[]{}); - greaterThanEqualDamage = new MutablePair(new CheckButtonRecipe(parent, 6, x, y + (15 * buttonCount++), "X>=Damage", false, "gted"), new Slider[]{new Slider("gted", 10, x - 2, parent.getGuiTop() + parent.getYSize() + 20, parent.getXSize() + 102, 20, "X= ", "", 0, 0, 0, false, true, new GuiSlider.ISlider() { - @Override - public void onChangeSliderValue(GuiSlider slider) { - if (parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { - parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); - } + // matchNotEmpty = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Match Not Empty", false, "matchNotEmpty"), new Slider[]{}); + useOreDict = new MutablePair<>(new CheckButtonRecipe(parent, 1, x, y + (15 * buttonCount++), "Ore Dictionary", false, "oreDictionary"), new Slider[]{}); + matchAnyMetadata = new MutablePair<>(new CheckButtonRecipe(parent, 2, x, y + (15 * buttonCount++), "Any Metadata", false, "anyMetadata"), new Slider[]{}); + anyDamage = new MutablePair<>(new CheckButtonRecipe(parent, 3, x, y + (15 * buttonCount++), "Any Damage", false, "anyDamage"), new Slider[]{}); + onlyDamage = new MutablePair<>(new CheckButtonRecipe(parent, 4, x, y + (15 * buttonCount++), "Only Damage", false, "onlyDamage"), new Slider[]{}); + greaterThanEqualDamage = new MutablePair<>(new CheckButtonRecipe(parent, 6, x, y + (15 * buttonCount++), "X>=Damage", false, "gted"), new Slider[]{new Slider("gted", 10, x - 2, parent.getGuiTop() + parent.getYSize() + 20, parent.getXSize() + 102, 20, "X= ", "", 0, 0, 0, false, true, slider -> { + if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); } })}); - lessThanDamage = new MutablePair(new CheckButtonRecipe(parent, 7, x, y + (15 * buttonCount++), "Damage(new CheckButtonRecipe(parent, 7, x, y + (15 * buttonCount++), "Damage { + if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); } })}); - betweenDamage = new MutablePair(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "X(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "X { + if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); } - }), new Slider("betweenDamageY", 13, x - 2, parent.getGuiTop() + parent.getYSize() + 44, parent.getXSize() + 102, 20, "Y= ", "", 0, 0, 0, false, true, new GuiSlider.ISlider() { - @Override - public void onChangeSliderValue(GuiSlider slider) { - if (parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { - parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); - } + }), new Slider("betweenDamageY", 13, x - 2, parent.getGuiTop() + parent.getYSize() + 44, parent.getXSize() + 102, 20, "Y= ", "", 0, 0, 0, false, true, slider -> { + if(parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); } })}); - - nbt = new MutablePair(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "NBT", false, "nbt"), new Slider[]{}); - - reuse = new MutablePair(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Reuse", false, "reuse"), new Slider[]{}); - noReturn = new MutablePair(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "No Return", false, "noreturn"), new Slider[]{}); - - + + nbt = new MutablePair<>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "NBT", false, "nbt"), new Slider[]{}); + + reuse = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Reuse", false, "reuse"), new Slider[]{}); + noReturn = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount), "No Return", false, "noreturn"), new Slider[]{}); + + this.buttons.add(useOreDict); this.buttons.add(matchAnyMetadata); this.buttons.add(anyDamage); this.buttons.add(onlyDamage); - + this.buttons.add(greaterThanEqualDamage); this.buttons.add(lessThanDamage); this.buttons.add(betweenDamage); this.buttons.add(nbt); - - + + this.buttons.add(reuse); this.buttons.add(noReturn); - - for (Pair but : this.buttons) { + + for(Pair but : this.buttons) { parent.getButtonList().add(but.getLeft()); } - - useOreDict.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft(), nbt.getLeft()})); - matchAnyMetadata.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); - anyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); - onlyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); - - greaterThanEqualDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); - lessThanDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), betweenDamage.getLeft()})); - betweenDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft()})); - - nbt.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft()})); - noReturn.getLeft().setIncompatible(Arrays.asList(reuse.getLeft())); - reuse.getLeft().setIncompatible(Arrays.asList(noReturn.getLeft())); - - + + useOreDict.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft(), nbt.getLeft()})); + matchAnyMetadata.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + anyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + onlyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + + greaterThanEqualDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + lessThanDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), betweenDamage.getLeft()})); + betweenDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft()})); + + nbt.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft()})); + noReturn.getLeft().setIncompatible(Collections.singletonList(reuse.getLeft())); + reuse.getLeft().setIncompatible(Collections.singletonList(noReturn.getLeft())); + + } - + public void close(GuiBase parent) { this.parent = parent; - if (!parent.getButtonList().isEmpty()) { + if(!parent.getButtonList().isEmpty()) { this.parent.getButtonList().remove(useOreDict.getLeft()); this.parent.getButtonList().remove(matchAnyMetadata.getLeft()); this.parent.getButtonList().remove(anyDamage.getLeft()); @@ -136,29 +113,29 @@ public class GuiMenu { this.parent.getButtonList().remove(greaterThanEqualDamage.getLeft()); this.parent.getButtonList().remove(lessThanDamage.getLeft()); this.parent.getButtonList().remove(betweenDamage.getLeft()); - + this.parent.getButtonList().remove(reuse.getLeft()); this.parent.getButtonList().remove(noReturn.getLeft()); - + } } - - + + public void setState(boolean active) { useOreDict.getLeft().setIsChecked(active); matchAnyMetadata.getLeft().setIsChecked(active); anyDamage.getLeft().setIsChecked(active); onlyDamage.getLeft().setIsChecked(active); - + greaterThanEqualDamage.getLeft().setIsChecked(active); lessThanDamage.getLeft().setIsChecked(active); betweenDamage.getLeft().setIsChecked(active); reuse.getLeft().setIsChecked(active); noReturn.getLeft().setIsChecked(active); nbt.getLeft().setIsChecked(active); - + } - + public void toggle(boolean active) { useOreDict.getLeft().enabled = active; matchAnyMetadata.getLeft().enabled = active; @@ -170,10 +147,10 @@ public class GuiMenu { reuse.getLeft().enabled = active; noReturn.getLeft().enabled = active; nbt.getLeft().enabled = active; - - + + } - + public void getFromMap(Map propertyMap, Map properties) { useOreDict.getLeft().setIsChecked(getPropertyFromMap(propertyMap, useOreDict.getLeft().getPropertyKey())); matchAnyMetadata.getLeft().setIsChecked(getPropertyFromMap(propertyMap, matchAnyMetadata.getLeft().getPropertyKey())); @@ -186,47 +163,47 @@ public class GuiMenu { noReturn.getLeft().setIsChecked(getPropertyFromMap(propertyMap, noReturn.getLeft().getPropertyKey())); nbt.getLeft().setIsChecked(getPropertyFromMap(propertyMap, nbt.getLeft().getPropertyKey())); } - + boolean getPropertyFromMap(Map propertyMap, String key) { - if (propertyMap.containsKey(key)) { + if(propertyMap.containsKey(key)) { return propertyMap.get(key); } return false; } - + Object getProperty(Map propertyMap, String key) { - if (propertyMap.containsKey(key)) { + if(propertyMap.containsKey(key)) { return propertyMap.get(key); } return false; } - + public int getX() { return x; } - + public int getY() { return y; } - + public int getWidth() { return 11; } - + public int getHeight() { return 55; } - - + + public Slider[] getSliders(CheckButtonRecipe check) { - for (Pair pair : this.buttons) { - if (pair.getLeft().getPropertyKey().equals(check.getPropertyKey())) { + for(Pair pair : this.buttons) { + if(pair.getLeft().getPropertyKey().equals(check.getPropertyKey())) { return pair.getValue(); } } return new Slider[0]; } - + public List> getButtons() { return buttons; } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java index 01c12f3..bbf93e4 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java @@ -1,13 +1,8 @@ package com.blamejared.ctgui.client.gui.craftingtable; -import com.blamejared.ctgui.api.ContainerBase; -import com.blamejared.ctgui.api.SlotRecipe; -import com.blamejared.ctgui.api.SlotRecipeOutput; +import com.blamejared.ctgui.api.*; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryCraftResult; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.Slot; +import net.minecraft.inventory.*; /** * Created by Jared. @@ -21,28 +16,21 @@ public class ContainerCraftingTable extends ContainerBase { //output this.addSlotToContainer(new SlotRecipeOutput(craftResult, 0, 124, 35)); //Slots - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) { + for(int i = 0; i < 3; ++i) { + for(int j = 0; j < 3; ++j) { this.addSlotToContainer(new SlotRecipe(craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18)); } } //Player - for (int x = 0; x < 9; x++) { + for(int x = 0; x < 9; x++) { addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142)); } - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 9; x++) { + for(int y = 0; y < 3; y++) { + for(int x = 0; x < 9; x++) { addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18)); } } } - @Override - protected Slot addSlotToContainer(Slot slotIn) { - if (slotIn instanceof SlotRecipe) { - getRecipeSlots().add((SlotRecipe) slotIn); - } - return super.addSlotToContainer(slotIn); - } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java index 6a6b1ba..a17c1d8 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java @@ -1,26 +1,21 @@ package com.blamejared.ctgui.client.gui.craftingtable; -import com.blamejared.ctgui.api.CheckButton; -import com.blamejared.ctgui.api.ContainerBase; -import com.blamejared.ctgui.api.GuiBase; -import com.blamejared.ctgui.api.SlotRecipe; -import net.minecraft.client.gui.GuiButton; +import com.blamejared.ctgui.api.*; import net.minecraft.util.ResourceLocation; -import java.util.Arrays; +import java.util.*; /** * Created by Jared. */ public class GuiCraftingTable extends GuiBase { - public GuiCraftingTable(ContainerBase container) { - super(container, 176, 166, true); - } - private CheckButton shaped; private CheckButton shapeless; private CheckButton mirror; + public GuiCraftingTable(ContainerBase container) { + super(container, 176, 166, true); + } @Override public void initGui() { @@ -35,9 +30,9 @@ public class GuiCraftingTable extends GuiBase { getButtonList().add(shapeless); getButtonList().add(shaped); getButtonList().add(mirror); - shaped.setIncompatible(Arrays.asList(shapeless)); - shapeless.setIncompatible(Arrays.asList(shaped, mirror)); - mirror.setIncompatible(Arrays.asList(remove)); + shaped.setIncompatible(Collections.singletonList(shapeless)); + shapeless.setIncompatible(Arrays.asList(shaped, mirror)); + mirror.setIncompatible(Collections.singletonList(remove)); shaped.setIsChecked(true); } @@ -46,52 +41,47 @@ public class GuiCraftingTable extends GuiBase { public String getOutputAdd() { String type = "add"; boolean shapel = false; - if (shapeless.isChecked()) { + if(shapeless.isChecked()) { type += "Shapeless"; shapel = true; - } else if (shaped.isChecked()) { + } else if(shaped.isChecked()) { type += "Shaped"; } - if (mirror.isChecked()) { + if(mirror.isChecked()) { type += "Mirrored"; } - if (shapel) { - return String.format("recipes.%s(%s, [%s%s%s%s%s%s%s%s%s]);", type, container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1)), getShapelessItem(container.getRecipeSlots().get(2)), getShapelessItem(container.getRecipeSlots().get(3)), getShapelessItem(container.getRecipeSlots().get(4)), getShapelessItem(container.getRecipeSlots().get(5)), getShapelessItem(container.getRecipeSlots().get(6)), getShapelessItem(container.getRecipeSlots().get(7)), getShapelessItem(container.getRecipeSlots().get(8)), getShapelessItem(container.getRecipeSlots().get(9))); + if(shapel) { + return String.format("recipes.%s(%s, [%s%s%s%s%s%s%s%s%s]);", type, container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1), true), getShapelessItem(container.getRecipeSlots().get(2), false), getShapelessItem(container.getRecipeSlots().get(3), false), getShapelessItem(container.getRecipeSlots().get(4), false), getShapelessItem(container.getRecipeSlots().get(5), false), getShapelessItem(container.getRecipeSlots().get(6), false), getShapelessItem(container.getRecipeSlots().get(7), false), getShapelessItem(container.getRecipeSlots().get(8), false), getShapelessItem(container.getRecipeSlots().get(9), false)); } return String.format("recipes.%s(%s, [[%s, %s, %s],[%s, %s, %s], [%s, %s, %s]]);", type, container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), container.getRecipeSlots().get(2).getItemString(), container.getRecipeSlots().get(3).getItemString(), container.getRecipeSlots().get(4).getItemString(), container.getRecipeSlots().get(5).getItemString(), container.getRecipeSlots().get(6).getItemString(), container.getRecipeSlots().get(7).getItemString(), container.getRecipeSlots().get(8).getItemString(), container.getRecipeSlots().get(9).getItemString()); } - private String getShapelessItem(SlotRecipe slot) { + private String getShapelessItem(SlotRecipe slot, boolean first) { String ret = ""; - if (slot.getHasStack()) { - ret += "," + slot.getItemString(); + if(slot.getHasStack()) { + if(!first) { + ret += ", "; + } + ret += slot.getItemString(); } - return ret.isEmpty() ? ret : ret.substring(1); + return ret.isEmpty() ? ret : ret; } - + @Override public String getOutputRemove() { boolean hasrecipe = false; - for (int i = 1; i < container.getRecipeSlots().size(); i++) { + for(int i = 1; i < container.getRecipeSlots().size(); i++) { SlotRecipe slot = container.getRecipeSlots().get(i); - if (slot.getHasStack()) { + if(slot.getHasStack()) { hasrecipe = true; } } - - String type = "remove"; - boolean shapel = false; - if (hasrecipe) - if (shapeless.isChecked()) { - type += "Shapeless"; - shapel = true; - } else if (shaped.isChecked()) { - type += "Shaped"; - } - if (shapel) { - return String.format("recipes.%s(%s, [%s%s%s%s%s%s%s%s%s]);", type, container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1)), getShapelessItem(container.getRecipeSlots().get(2)), getShapelessItem(container.getRecipeSlots().get(3)), getShapelessItem(container.getRecipeSlots().get(4)), getShapelessItem(container.getRecipeSlots().get(5)), getShapelessItem(container.getRecipeSlots().get(6)), getShapelessItem(container.getRecipeSlots().get(7)), getShapelessItem(container.getRecipeSlots().get(8)), getShapelessItem(container.getRecipeSlots().get(9))); + + boolean shapel = shapeless.isChecked(); + if(shapel) { + return String.format("recipes.removeShapeless(%s, [%s%s%s%s%s%s%s%s%s]);", container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1), true), getShapelessItem(container.getRecipeSlots().get(2), false), getShapelessItem(container.getRecipeSlots().get(3), false), getShapelessItem(container.getRecipeSlots().get(4), false), getShapelessItem(container.getRecipeSlots().get(5), false), getShapelessItem(container.getRecipeSlots().get(6), false), getShapelessItem(container.getRecipeSlots().get(7), false), getShapelessItem(container.getRecipeSlots().get(8), false), getShapelessItem(container.getRecipeSlots().get(9), false)); } - return hasrecipe ? String.format("recipes.%s(%s, [[%s, %s, %s],[%s, %s, %s], [%s, %s, %s]]);", type, container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), container.getRecipeSlots().get(2).getItemString(), container.getRecipeSlots().get(3).getItemString(), container.getRecipeSlots().get(4).getItemString(), container.getRecipeSlots().get(5).getItemString(), container.getRecipeSlots().get(6).getItemString(), container.getRecipeSlots().get(7).getItemString(), container.getRecipeSlots().get(8).getItemString(), container.getRecipeSlots().get(9).getItemString()) : String.format("recipes.removeShaped(%s);", container.getRecipeSlots().get(0).getItemString()); + return hasrecipe ? String.format("recipes.removeShaped(%s, [[%s, %s, %s],[%s, %s, %s], [%s, %s, %s]]);", container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), container.getRecipeSlots().get(2).getItemString(), container.getRecipeSlots().get(3).getItemString(), container.getRecipeSlots().get(4).getItemString(), container.getRecipeSlots().get(5).getItemString(), container.getRecipeSlots().get(6).getItemString(), container.getRecipeSlots().get(7).getItemString(), container.getRecipeSlots().get(8).getItemString(), container.getRecipeSlots().get(9).getItemString()) : String.format("recipes.remove(%s);", container.getRecipeSlots().get(0).getItemString()); } @Override diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java index 1eae450..42889e1 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java @@ -1,13 +1,9 @@ package com.blamejared.ctgui.client.gui.furnace; -import com.blamejared.ctgui.api.ContainerBase; -import com.blamejared.ctgui.api.SlotRecipe; -import com.blamejared.ctgui.api.SlotRecipeOutput; +import com.blamejared.ctgui.api.*; import com.blamejared.ctgui.client.InventoryFake; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryCraftResult; -import net.minecraft.inventory.Slot; +import net.minecraft.inventory.*; /** * Created by Jared. @@ -25,22 +21,16 @@ public class ContainerFurnace extends ContainerBase { this.addSlotToContainer(new SlotRecipe(inventory, 0, 56, 17)); //Player - for (int x = 0; x < 9; x++) { + for(int x = 0; x < 9; x++) { addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142)); } - for (int y = 0; y < 3; y++) { - for (int x = 0; x < 9; x++) { + for(int y = 0; y < 3; y++) { + for(int x = 0; x < 9; x++) { addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18)); } } } - @Override - protected Slot addSlotToContainer(Slot slotIn) { - if (slotIn instanceof SlotRecipe) { - getRecipeSlots().add((SlotRecipe) slotIn); - } - return super.addSlotToContainer(slotIn); - } + } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java index 63c542e..bae9f6d 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java @@ -1,14 +1,13 @@ package com.blamejared.ctgui.client.gui.furnace; -import com.blamejared.ctgui.api.ContainerBase; -import com.blamejared.ctgui.api.GuiBase; -import com.blamejared.ctgui.api.Slider; +import com.blamejared.ctgui.api.*; import net.minecraft.util.ResourceLocation; /** * Created by Jared. */ public class GuiFurnace extends GuiBase { + private Slider xpSlider; public GuiFurnace(ContainerBase container) { @@ -25,7 +24,7 @@ public class GuiFurnace extends GuiBase { @Override public void updateScreen() { super.updateScreen(); - if (!container.getRecipeSlots().get(1).getHasStack()) { + if(!container.getRecipeSlots().get(1).getHasStack()) { add.enabled = false; remove.enabled = false; } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java index 5906d07..902e6a0 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java @@ -2,9 +2,7 @@ package com.blamejared.ctgui.commands; import com.blamejared.ctgui.MTRecipe; import com.blamejared.ctgui.api.GuiRegistry; -import net.minecraft.command.CommandBase; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommandSender; +import net.minecraft.command.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.TextComponentString; @@ -15,12 +13,12 @@ import net.minecraft.util.text.TextComponentString; public class CommandCTGUI extends CommandBase { @Override - public String getCommandName() { + public String getName() { return "CTGUI"; } @Override - public String getCommandUsage(ICommandSender sender) { + public String getUsage(ICommandSender sender) { return "CTGUI "; } @@ -31,12 +29,12 @@ public class CommandCTGUI extends CommandBase { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - if (args.length == 0 || Integer.parseInt(args[0]) < 1 || GuiRegistry.getHandlerForID(Integer.parseInt(args[0])) == null) { - sender.addChatMessage(new TextComponentString("Invalid ID!")); + if(args.length == 0 || Integer.parseInt(args[0]) < 1 || GuiRegistry.getHandlerForID(Integer.parseInt(args[0])) == null) { + sender.sendMessage(new TextComponentString("Invalid ID!")); return; } - if (sender instanceof EntityPlayer) { + if(sender instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) sender; player.openGui(MTRecipe.INSTANCE, Integer.parseInt(args[0]), sender.getEntityWorld(), 0, 0, 0); } diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java index b15330e..22dd56a 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java @@ -12,7 +12,7 @@ public class ClientProxy extends CommonProxy { @Override public EntityPlayer getPlayer() { - return Minecraft.getMinecraft().thePlayer; + return Minecraft.getMinecraft().player; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java index 9a13670..885bd97 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/api/minecraft/MineTweakerMC.java @@ -1,496 +1,508 @@ package minetweaker.api.minecraft; import minetweaker.MineTweakerAPI; -import minetweaker.api.block.IBlock; -import minetweaker.api.block.IBlockDefinition; +import minetweaker.api.block.*; import minetweaker.api.data.IData; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import minetweaker.api.item.IngredientUnknown; +import minetweaker.api.item.*; import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.oredict.IOreDictEntry; import minetweaker.api.player.IPlayer; -import minetweaker.api.world.IBiome; -import minetweaker.api.world.IDimension; -import minetweaker.mc1102.block.MCBlockDefinition; -import minetweaker.mc1102.block.MCSpecificBlock; -import minetweaker.mc1102.block.MCWorldBlock; +import minetweaker.api.world.*; +import minetweaker.mc1102.block.*; import minetweaker.mc1102.data.NBTConverter; import minetweaker.mc1102.item.MCItemStack; import minetweaker.mc1102.liquid.MCLiquidStack; import minetweaker.mc1102.oredict.MCOreDictEntry; import minetweaker.mc1102.player.MCPlayer; -import minetweaker.mc1102.world.MCBiome; -import minetweaker.mc1102.world.MCDimension; +import minetweaker.mc1102.world.*; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; +import net.minecraft.item.*; +import net.minecraft.nbt.*; +import net.minecraft.world.*; import net.minecraft.world.biome.Biome; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * MineTweaker - MineCraft API bridge. - * + * * @author Stan Hebben */ public class MineTweakerMC { - private static final Map blockDefinitions = new HashMap(); - public static final IBiome[] biomes; - - static { - biomes = new IBiome[Biome.REGISTRY.getKeys().size()]; - for (int i = 0; i items = ingredient.getItems(); - if (items.size() != 1) { - MineTweakerAPI.logError("Not an ingredient with a single item: " + ingredient); - } - return getItemStack(items.get(0)); - } - - /** - * Returns the MineTweaker item stack for this item. - * - * @param item minecraft item stack - * @return minetweaker item stack - */ - public static IItemStack getIItemStack(ItemStack item) { - if (item == null) - return null; - - return new MCItemStack(item); - } - - /** - * Constructs an item stack with wildcard size. - * - * @param item minecraft item stack - * @return minetweaker stack - */ - public static IItemStack getIItemStackWildcardSize(ItemStack item) { - if (item == null) - return null; - - return new MCItemStack(item, true); - } - - /** - * Constructs an item stack with wildcard size. - * - * @param item - * @param meta - * @return minetweaker stack - */ - public static IItemStack getIItemStackWildcardSize(Item item, int meta) { - if (item == null) - return null; - - return new MCItemStack(new ItemStack(item, 1, meta), true); - } - - /** - * Constructs an item stack with wildcard damage. - * - * @param item stack item - * @param amount stack size - * @return minetweaker item stack - */ - public static IItemStack getIItemStackWildcard(Item item, int amount) { - if (item == null) - return null; - - return new MCItemStack(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE)); - } - - public static ItemStack[] getExamples(IIngredient ingredient) { - List examples = ingredient.getItems(); - ItemStack[] result = new ItemStack[examples.size()]; - for (int i = 0; i < examples.size(); i++) { - result[i] = MineTweakerMC.getItemStack(examples.get(i)); - } - return result; - } - - /** - * Constructs an item stack with given item, damage and amount. - * - * @param item stack item - * @param damage stack damage - * @param amount stack amount - * @return minetweaker item stack - */ - public static IItemStack getItemStack(Item item, int amount, int damage) { - if (item == null) - return null; - - return new MCItemStack(new ItemStack(item, amount, damage)); - } - - /** - * Converts an array of minetweaker item stacks into an array of minecraft - * item stacks. - * - * @param items minetweker item stacks - * @return minecraft item stacks - */ - public static ItemStack[] getItemStacks(IItemStack... items) { - if (items == null) - return null; - - ItemStack[] output = new ItemStack[items.length]; - for (int i = 0; i < items.length; i++) { - Object internal = items[i].getInternal(); - if (internal != null && internal instanceof ItemStack) { - output[i] = (ItemStack) internal; - } - } - return output; - } - - /** - * Converts a list of minetweaker item stacks into an array of minecraft - * item stacks. - * - * @param items minetweaker items - * @return minecraft items - */ - public static ItemStack[] getItemStacks(List items) { - if (items == null) - return null; - - ItemStack[] output = new ItemStack[items.size()]; - for (int i = 0; i < items.size(); i++) { - Object internal = items.get(i).getInternal(); - if (internal != null && internal instanceof ItemStack) { - output[i] = (ItemStack) internal; - } else { - MineTweakerAPI.logError("Invalid item stack: " + items.get(i)); - } - } - return output; - } - - /** - * Converts an array of minecraft item stacks into an array of minetweaker - * item stacks. - * - * @param items minecraft item stacks - * @return minetweaker item stacks - */ - public static IItemStack[] getIItemStacks(ItemStack... items) { - if (items == null) - return null; - - IItemStack[] result = new IItemStack[items.length]; - for (int i = 0; i < items.length; i++) { - result[i] = new MCItemStack(items[i]); - } - return result; - } - - /** - * Converts a list of minecraft item stacks into an array of minetweaker - * item stacks. - * - * @param items minecraft item stacks - * @return minetweaker item stacks - */ - public static IItemStack[] getIItemStacks(List items) { - if (items == null) - return null; - - IItemStack[] result = new IItemStack[items.size()]; - for (int i = 0; i < result.length; i++) { - result[i] = new MCItemStack(items.get(i)); - } - return result; - } - - /** - * Gets the ore dictionary entry with the given name. If the entry didn't - * exist yet, it will create it and return an empty entry. - * - * @param name ore entry name - * @return ore dictionary entry - */ - public static IOreDictEntry getOreDict(String name) { - return new MCOreDictEntry(name); - } - - /** - * Converts a Minecraft player into a MineTweaker player. - * - * @param player minecraft player - * @return minetweaker player - */ - public static IPlayer getIPlayer(EntityPlayer player) { - if (player == null) - return null; - - return new MCPlayer(player); - } - - /** - * Converts a MineTweaker player into a Minecraft player. - * - * @param player minetweaker player - * @return minecraft player - */ - public static EntityPlayer getPlayer(IPlayer player) { - if (player == null) - return null; - - if (!(player instanceof MCPlayer)) { - MineTweakerAPI.logError("Invalid player: " + player); - } - - return ((MCPlayer) player).getInternal(); - } - - /** - * Converts a Minecraft NBT to an IData instance. The IData instance is - * immutable (not modifyiable). - * - * @param nbt nbt data - * @return IData value - */ - public static IData getIData(NBTBase nbt) { - if (nbt == null) - return null; - - return NBTConverter.from(nbt, true); - } - - /** - * Converts a Minecraft NBT to a modifyable IData instance. - * - * @param nbt nbt data - * @return mutable IData value - */ - public static IData getIDataModifyable(NBTBase nbt) { - if (nbt == null) - return null; - - return NBTConverter.from(nbt, false); - } - - /** - * Converts an IData instance to an NBT value. - * - * @param data IData value - * @return nbt data - */ - public static NBTBase getNBT(IData data) { - if (data == null) - return null; - - return NBTConverter.from(data); - } - - /** - * Converts an IData instance to an NBT Tag compound. - * - * @param data IData value - * @return nbt compound data - */ - public static NBTTagCompound getNBTCompound(IData data) { - if (data == null) - return null; - - return (NBTTagCompound) NBTConverter.from(data); - } - - /** - * Retrieves the block at the given position. - * - * @param blocks block access - * @param x block x position - * @param y block y position - * @param z block z position - * @return block instance - */ - public static IBlock getBlock(IBlockAccess blocks, int x, int y, int z) { - return new MCWorldBlock(blocks, x, y, z); - } - - /** - * Retrieves the block definition for the given block. - * - * @param block block object - * @return block definition - */ - public static IBlockDefinition getBlockDefinition(Block block) { - if (!blockDefinitions.containsKey(block)) { - blockDefinitions.put(block, new MCBlockDefinition(block)); - } - return blockDefinitions.get(block); - } - - /** - * Retrieves the dimension instance for a given world. - * - * @param world world - * @return dimension - */ - public static IDimension getDimension(World world) { - if (world == null) - return null; - - return new MCDimension(world); - } - - /** - * Returns an instance of the given block. - * - * @param block MC block definition - * @return MT block instance - */ - public static IBlock getBlockAnyMeta(Block block) { - return new MCSpecificBlock(block, OreDictionary.WILDCARD_VALUE); - } - - /** - * Returns an instance of the given block. - * - * @param block MC block definition - * @param meta block meta value - * @return MT block instance - */ - public static IBlock getBlock(Block block, int meta) { - return new MCSpecificBlock(block, meta); - } - - /** - * Retrieves the block from an item stack. - * - * @param itemStack - * @return - */ - public static Block getBlock(IItemStack itemStack) { - return ((MCBlockDefinition) itemStack.asBlock().getDefinition()).getInternalBlock(); - } - - public static Block getBlock(IBlock block) { - return ((MCBlockDefinition) block.getDefinition()).getInternalBlock(); - } - - /** - * Retrieves the internal fluid stack of the given stack. - * - * @param stack MT liquid stack - * @return MCF fluid stack - */ - public static FluidStack getLiquidStack(ILiquidStack stack) { - if (stack == null) - return null; - - return (FluidStack) stack.getInternal(); - } - - /** - * Converts an array of MT liquid stacks into an array of MCF fluid stacks - * - */ - public static FluidStack[] getLiquidStacks(ILiquidStack[] stacks) { - if (stacks == null) { - return null; - } - - FluidStack[] res = new FluidStack[stacks.length]; - - for (int i = 0; i < stacks.length; i++) { - ILiquidStack liquidStack = stacks[i]; - res[i] = getLiquidStack(liquidStack); - } - return res; - } - - private static final HashMap oreDictArrays = new HashMap(); - - public static IOreDictEntry getOreDictEntryFromArray(List array) { - if (!oreDictArrays.containsKey(array)) { - for (String ore : OreDictionary.getOreNames()) { - if (OreDictionary.getOres(ore) == array) { - oreDictArrays.put(array, MineTweakerAPI.oreDict.get(ore)); - } - } - } - - return oreDictArrays.get(array); - } - - /** - * Converts a Minecraft ingredient to a MineTweaker ingredient. - * - * @param ingredient minecraft ingredient - * @return minetweaker ingredient - */ - public static IIngredient getIIngredient(Object ingredient) { - if (ingredient == null) { - return null; - } else if (ingredient instanceof String) { - return MineTweakerAPI.oreDict.get((String) ingredient); - } else if (ingredient instanceof Item) { - return getIItemStack(new ItemStack((Item) ingredient, 1, 0)); - } else if (ingredient instanceof ItemStack) { - return getIItemStack((ItemStack) ingredient); - } else if (ingredient instanceof List) { - IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient); - - if (entry == null) { - return IngredientUnknown.INSTANCE; - } - - return entry; - } else if (ingredient instanceof FluidStack) { - return new MCLiquidStack((FluidStack) ingredient); - } else { - throw new IllegalArgumentException("Not a valid ingredient: " + ingredient); - } - } + + public static final IBiome[] biomes; + private static final Map blockDefinitions = new HashMap<>(); + private static final HashMap oreDictArrays = new HashMap(); + static { + biomes = new IBiome[Biome.REGISTRY.getKeys().size()]; + for(int i = 0; i < Biome.REGISTRY.getKeys().size(); i++) { + if(Biome.REGISTRY.getObjectById(i) != null) + biomes[i] = new MCBiome(Biome.REGISTRY.getObjectById(i)); + } + } + + private MineTweakerMC() { + } + + /** + * Returns the Minecraft item for this MineTweaker item. + * + * @param item minetweaker item stack + * + * @return minecraft item stack + */ + public static ItemStack getItemStack(IItemStack item) { + if(item == null) + return null; + + Object internal = item.getInternal(); + if(internal == null || !(internal instanceof ItemStack)) { + MineTweakerAPI.logError("Not a valid item stack: " + item); + } + return (ItemStack) internal; + } + + /** + * Returns the Minecraft ingredient for this ingredient. This method is only + * useful for ingredients that represent a single item stack. + * + * @param ingredient item ingredient + * + * @return minecraft item stack + */ + public static ItemStack getItemStack(IIngredient ingredient) { + if(ingredient == null) + return null; + + List items = ingredient.getItems(); + if(items.size() != 1) { + MineTweakerAPI.logError("Not an ingredient with a single item: " + ingredient); + } + return getItemStack(items.get(0)); + } + + /** + * Returns the MineTweaker item stack for this item. + * + * @param item minecraft item stack + * + * @return minetweaker item stack + */ + public static IItemStack getIItemStack(ItemStack item) { + if(item == null) + return null; + + return new MCItemStack(item); + } + + /** + * Constructs an item stack with wildcard size. + * + * @param item minecraft item stack + * + * @return minetweaker stack + */ + public static IItemStack getIItemStackWildcardSize(ItemStack item) { + if(item == null) + return null; + + return new MCItemStack(item, true); + } + + /** + * Constructs an item stack with wildcard size. + * + * @param item + * @param meta + * + * @return minetweaker stack + */ + public static IItemStack getIItemStackWildcardSize(Item item, int meta) { + if(item == null) + return null; + + return new MCItemStack(new ItemStack(item, 1, meta), true); + } + + /** + * Constructs an item stack with wildcard damage. + * + * @param item stack item + * @param amount stack size + * + * @return minetweaker item stack + */ + public static IItemStack getIItemStackWildcard(Item item, int amount) { + if(item == null) + return null; + + return new MCItemStack(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE)); + } + + public static ItemStack[] getExamples(IIngredient ingredient) { + List examples = ingredient.getItems(); + ItemStack[] result = new ItemStack[examples.size()]; + for(int i = 0; i < examples.size(); i++) { + result[i] = MineTweakerMC.getItemStack(examples.get(i)); + } + return result; + } + + /** + * Constructs an item stack with given item, damage and amount. + * + * @param item stack item + * @param damage stack damage + * @param amount stack amount + * + * @return minetweaker item stack + */ + public static IItemStack getItemStack(Item item, int amount, int damage) { + if(item == null) + return null; + + return new MCItemStack(new ItemStack(item, amount, damage)); + } + + /** + * Converts an array of minetweaker item stacks into an array of minecraft + * item stacks. + * + * @param items minetweker item stacks + * + * @return minecraft item stacks + */ + public static ItemStack[] getItemStacks(IItemStack... items) { + if(items == null) + return null; + + ItemStack[] output = new ItemStack[items.length]; + for(int i = 0; i < items.length; i++) { + Object internal = items[i].getInternal(); + if(internal != null && internal instanceof ItemStack) { + output[i] = (ItemStack) internal; + } + } + return output; + } + + /** + * Converts a list of minetweaker item stacks into an array of minecraft + * item stacks. + * + * @param items minetweaker items + * + * @return minecraft items + */ + public static ItemStack[] getItemStacks(List items) { + if(items == null) + return null; + + ItemStack[] output = new ItemStack[items.size()]; + for(int i = 0; i < items.size(); i++) { + Object internal = items.get(i).getInternal(); + if(internal != null && internal instanceof ItemStack) { + output[i] = (ItemStack) internal; + } else { + MineTweakerAPI.logError("Invalid item stack: " + items.get(i)); + } + } + return output; + } + + /** + * Converts an array of minecraft item stacks into an array of minetweaker + * item stacks. + * + * @param items minecraft item stacks + * + * @return minetweaker item stacks + */ + public static IItemStack[] getIItemStacks(ItemStack... items) { + if(items == null) + return null; + + IItemStack[] result = new IItemStack[items.length]; + for(int i = 0; i < items.length; i++) { + result[i] = new MCItemStack(items[i]); + } + return result; + } + + /** + * Converts a list of minecraft item stacks into an array of minetweaker + * item stacks. + * + * @param items minecraft item stacks + * + * @return minetweaker item stacks + */ + public static IItemStack[] getIItemStacks(List items) { + if(items == null) + return null; + + IItemStack[] result = new IItemStack[items.size()]; + for(int i = 0; i < result.length; i++) { + result[i] = new MCItemStack(items.get(i)); + } + return result; + } + + /** + * Gets the ore dictionary entry with the given name. If the entry didn't + * exist yet, it will create it and return an empty entry. + * + * @param name ore entry name + * + * @return ore dictionary entry + */ + public static IOreDictEntry getOreDict(String name) { + return new MCOreDictEntry(name); + } + + /** + * Converts a Minecraft player into a MineTweaker player. + * + * @param player minecraft player + * + * @return minetweaker player + */ + public static IPlayer getIPlayer(EntityPlayer player) { + if(player == null) + return null; + + return new MCPlayer(player); + } + + /** + * Converts a MineTweaker player into a Minecraft player. + * + * @param player minetweaker player + * + * @return minecraft player + */ + public static EntityPlayer getPlayer(IPlayer player) { + if(player == null) + return null; + + if(!(player instanceof MCPlayer)) { + MineTweakerAPI.logError("Invalid player: " + player); + } + + return ((MCPlayer) player).getInternal(); + } + + /** + * Converts a Minecraft NBT to an IData instance. The IData instance is + * immutable (not modifyiable). + * + * @param nbt nbt data + * + * @return IData value + */ + public static IData getIData(NBTBase nbt) { + if(nbt == null) + return null; + + return NBTConverter.from(nbt, true); + } + + /** + * Converts a Minecraft NBT to a modifyable IData instance. + * + * @param nbt nbt data + * + * @return mutable IData value + */ + public static IData getIDataModifyable(NBTBase nbt) { + if(nbt == null) + return null; + + return NBTConverter.from(nbt, false); + } + + /** + * Converts an IData instance to an NBT value. + * + * @param data IData value + * + * @return nbt data + */ + public static NBTBase getNBT(IData data) { + if(data == null) + return null; + + return NBTConverter.from(data); + } + + /** + * Converts an IData instance to an NBT Tag compound. + * + * @param data IData value + * + * @return nbt compound data + */ + public static NBTTagCompound getNBTCompound(IData data) { + if(data == null) + return null; + + return (NBTTagCompound) NBTConverter.from(data); + } + + /** + * Retrieves the block at the given position. + * + * @param blocks block access + * @param x block x position + * @param y block y position + * @param z block z position + * + * @return block instance + */ + public static IBlock getBlock(IBlockAccess blocks, int x, int y, int z) { + return new MCWorldBlock(blocks, x, y, z); + } + + /** + * Retrieves the block definition for the given block. + * + * @param block block object + * + * @return block definition + */ + public static IBlockDefinition getBlockDefinition(Block block) { + if(!blockDefinitions.containsKey(block)) { + blockDefinitions.put(block, new MCBlockDefinition(block)); + } + return blockDefinitions.get(block); + } + + /** + * Retrieves the dimension instance for a given world. + * + * @param world world + * + * @return dimension + */ + public static IDimension getDimension(World world) { + if(world == null) + return null; + + return new MCDimension(world); + } + + /** + * Returns an instance of the given block. + * + * @param block MC block definition + * + * @return MT block instance + */ + public static IBlock getBlockAnyMeta(Block block) { + return new MCSpecificBlock(block, OreDictionary.WILDCARD_VALUE); + } + + /** + * Returns an instance of the given block. + * + * @param block MC block definition + * @param meta block meta value + * + * @return MT block instance + */ + public static IBlock getBlock(Block block, int meta) { + return new MCSpecificBlock(block, meta); + } + + /** + * Retrieves the block from an item stack. + * + * @param itemStack + * + * @return + */ + public static Block getBlock(IItemStack itemStack) { + return ((MCBlockDefinition) itemStack.asBlock().getDefinition()).getInternalBlock(); + } + + public static Block getBlock(IBlock block) { + return ((MCBlockDefinition) block.getDefinition()).getInternalBlock(); + } + + /** + * Retrieves the internal fluid stack of the given stack. + * + * @param stack MT liquid stack + * + * @return MCF fluid stack + */ + public static FluidStack getLiquidStack(ILiquidStack stack) { + if(stack == null) + return null; + + return (FluidStack) stack.getInternal(); + } + + /** + * Converts an array of MT liquid stacks into an array of MCF fluid stacks + */ + public static FluidStack[] getLiquidStacks(ILiquidStack[] stacks) { + if(stacks == null) { + return null; + } + + FluidStack[] res = new FluidStack[stacks.length]; + + for(int i = 0; i < stacks.length; i++) { + ILiquidStack liquidStack = stacks[i]; + res[i] = getLiquidStack(liquidStack); + } + return res; + } + + public static IOreDictEntry getOreDictEntryFromArray(List array) { + if(!oreDictArrays.containsKey(array)) { + for(String ore : OreDictionary.getOreNames()) { + if(OreDictionary.getOres(ore) == array) { + oreDictArrays.put(array, MineTweakerAPI.oreDict.get(ore)); + } + } + } + + return oreDictArrays.get(array); + } + + /** + * Converts a Minecraft ingredient to a MineTweaker ingredient. + * + * @param ingredient minecraft ingredient + * + * @return minetweaker ingredient + */ + public static IIngredient getIIngredient(Object ingredient) { + if(ingredient == null) { + return null; + } else if(ingredient instanceof String) { + return MineTweakerAPI.oreDict.get((String) ingredient); + } else if(ingredient instanceof Item) { + return getIItemStack(new ItemStack((Item) ingredient, 1, 0)); + } else if(ingredient instanceof ItemStack) { + return getIItemStack((ItemStack) ingredient); + } else if(ingredient instanceof List) { + IOreDictEntry entry = getOreDictEntryFromArray((List) ingredient); + + if(entry == null) { + return IngredientUnknown.INSTANCE; + } + + return entry; + } else if(ingredient instanceof FluidStack) { + return new MCLiquidStack((FluidStack) ingredient); + } else { + throw new IllegalArgumentException("Not a valid ingredient: " + ingredient); + } + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/FMLEventHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/FMLEventHandler.java index f68638e..7848703 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/FMLEventHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/FMLEventHandler.java @@ -1,26 +1,29 @@ package minetweaker.mc1102; -import minetweaker.MineTweakerAPI; -import minetweaker.MineTweakerImplementationAPI; -import minetweaker.api.event.PlayerCraftedEvent; -import minetweaker.api.event.PlayerLoggedInEvent; -import minetweaker.api.event.PlayerLoggedOutEvent; -import minetweaker.api.event.PlayerSmeltedEvent; +import minetweaker.*; +import minetweaker.api.event.*; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.player.IPlayer; +import minetweaker.api.recipes.*; +import minetweaker.mc1102.item.MCItemStack; import minetweaker.mc1102.network.MineTweakerLoadScriptsPacket; +import minetweaker.mc1102.player.MCPlayer; import minetweaker.mc1102.recipes.MCCraftingInventory; +import minetweaker.mc1102.world.MCDimension; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.crafting.CraftingManager; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent; /** * @author Stan */ -public class FMLEventHandler{ +public class FMLEventHandler { + @SubscribeEvent - public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent ev){ - if(ev.player instanceof EntityPlayerMP){ + public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent ev) { + if(ev.player instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) ev.player; MineTweakerMod.NETWORK.sendTo(new MineTweakerLoadScriptsPacket(MineTweakerAPI.tweaker.getScriptData()), player); } @@ -29,26 +32,42 @@ public class FMLEventHandler{ } @SubscribeEvent - public void onPlayerItemCrafted(PlayerEvent.ItemCraftedEvent ev){ + public void onPlayerItemCrafted(PlayerEvent.ItemCraftedEvent ev) { IPlayer iPlayer = MineTweakerMC.getIPlayer(ev.player); - if(MineTweakerMod.INSTANCE.recipes.hasTransformerRecipes()){ + if(MineTweakerMod.INSTANCE.recipes.hasTransformerRecipes()) { MineTweakerMod.INSTANCE.recipes.applyTransformations(MCCraftingInventory.get(ev.craftMatrix, ev.player), iPlayer); } + if(ev.craftMatrix instanceof InventoryCrafting) { - if(MineTweakerImplementationAPI.events.hasPlayerCrafted()){ + CraftingManager.getInstance().getRecipeList().stream().filter(i -> i instanceof IMTRecipe && i.getRecipeOutput().isItemEqual(ev.crafting)).forEach(i -> { + IMTRecipe rec = (IMTRecipe) i; + if(rec.getRecipe() instanceof ShapedRecipe) { + ShapedRecipe r = (ShapedRecipe) rec.getRecipe(); + if(r.getAction() != null) { + r.getAction().process(new MCItemStack(ev.crafting), new CraftingInfo(new MCCraftingInventory(ev.craftMatrix, ev.player), new MCDimension(ev.player.world)), new MCPlayer(ev.player)); + } + } else if(rec.getRecipe() instanceof ShapelessRecipe) { + ShapelessRecipe r = (ShapelessRecipe) rec.getRecipe(); + if(r.getAction() != null) { + r.getAction().process(new MCItemStack(ev.crafting), new CraftingInfo(new MCCraftingInventory(ev.craftMatrix, ev.player), new MCDimension(ev.player.world)), new MCPlayer(ev.player)); + } + } + }); + } + if(MineTweakerImplementationAPI.events.hasPlayerCrafted()) { MineTweakerImplementationAPI.events.publishPlayerCrafted(new PlayerCraftedEvent(iPlayer, MineTweakerMC.getIItemStack(ev.crafting), MCCraftingInventory.get(ev.craftMatrix, ev.player))); } } @SubscribeEvent - public void onPlayerItemSmelted(PlayerEvent.ItemSmeltedEvent ev){ - if(MineTweakerImplementationAPI.events.hasPlayerSmelted()){ + public void onPlayerItemSmelted(PlayerEvent.ItemSmeltedEvent ev) { + if(MineTweakerImplementationAPI.events.hasPlayerSmelted()) { MineTweakerImplementationAPI.events.publishPlayerSmelted(new PlayerSmeltedEvent(MineTweakerMC.getIPlayer(ev.player), MineTweakerMC.getIItemStack(ev.smelting))); } } @SubscribeEvent - public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent ev){ + public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent ev) { MineTweakerImplementationAPI.events.publishPlayerLoggedOut(new PlayerLoggedOutEvent(MineTweakerMC.getIPlayer(ev.player))); } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/ForgeEventHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/ForgeEventHandler.java index 6c210af..6e073ce 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/ForgeEventHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/ForgeEventHandler.java @@ -1,35 +1,32 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102; -import minetweaker.MineTweakerImplementationAPI; +import minetweaker.*; +import minetweaker.api.entity.IEntityDefinition; import minetweaker.api.formatting.IFormattedText; import minetweaker.api.item.IItemStack; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.tooltip.IngredientTooltips; import minetweaker.mc1102.formatting.IMCFormattedString; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; -import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import minetweaker.mc1102.item.MCItemStack; +import net.minecraft.entity.*; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.entity.living.LivingDropsEvent; +import net.minecraftforge.event.entity.player.*; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.input.Keyboard; +import java.util.*; + /** * @author Stan */ public class ForgeEventHandler { + @SubscribeEvent public void onPlayerInteract(PlayerInteractEvent ev) { - minetweaker.api.event.PlayerInteractEvent event = new minetweaker.api.event.PlayerInteractEvent( - MineTweakerMC.getIPlayer(ev.getEntityPlayer()), - MineTweakerMC.getDimension(ev.getWorld()), - ev.getPos() == null ? 0 : ev.getPos().getX(), - ev.getPos() == null ? 0 : ev.getPos().getY(), - ev.getPos() == null ? 0 : ev.getPos().getZ()); - + minetweaker.api.event.PlayerInteractEvent event = new minetweaker.api.event.PlayerInteractEvent(MineTweakerMC.getIPlayer(ev.getEntityPlayer()), MineTweakerMC.getDimension(ev.getWorld()), ev.getPos() == null ? 0 : ev.getPos().getX(), ev.getPos() == null ? 0 : ev.getPos().getY(), ev.getPos() == null ? 0 : ev.getPos().getZ()); MineTweakerImplementationAPI.events.publishPlayerInteract(event); } @@ -50,4 +47,48 @@ public class ForgeEventHandler { } } } + + @SubscribeEvent + public void mobDrop(LivingDropsEvent ev) { + Entity entity = ev.getEntity(); + IEntityDefinition entityDefinition = MineTweakerAPI.game.getEntity(EntityList.getEntityString(ev.getEntity())); + if(entityDefinition != null) { + if(!entityDefinition.getDropsToAdd().isEmpty()) { + entityDefinition.getDropsToAdd().forEach((key, val) -> { + EntityItem item = null; + if(val.getMin() == 0 && val.getMax() == 0) { + item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy()); + } else { + item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy()); + } + ev.getDrops().add(item); + }); + } + if(ev.getSource().getEntity() instanceof EntityPlayer) { + if(!entityDefinition.getDropsToAddPlayerOnly().isEmpty()) { + entityDefinition.getDropsToAddPlayerOnly().forEach((key, val) -> { + EntityItem item = null; + if(val.getMin() == 0 && val.getMax() == 0) { + item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.getInternal()).copy()); + } else { + item = new EntityItem(entity.world, entity.posX + 0.5, entity.posY + 0.5, entity.posZ + 0.5, ((ItemStack) key.withAmount(val.getRandom()).getInternal()).copy()); + } + ev.getDrops().add(item); + }); + } + } + if(!entityDefinition.getDropsToRemove().isEmpty()) { + List removedDrops = new ArrayList<>(); + entityDefinition.getDropsToRemove().forEach(drop -> { + // if(drop.matches(new MCItemStack())) + ev.getDrops().forEach(drops -> { + if(drop.matches(new MCItemStack(drops.getEntityItem()))) { + removedDrops.add(drops); + } + }); + }); + ev.getDrops().removeAll(removedDrops); + } + } + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/GuiCannotRemodify.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/GuiCannotRemodify.java index 3501450..42e0fcc 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/GuiCannotRemodify.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/GuiCannotRemodify.java @@ -1,7 +1,6 @@ package minetweaker.mc1102; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.*; /** * This screen is shown when a client has been modified with a permanent @@ -10,36 +9,37 @@ import net.minecraft.client.gui.GuiScreen; * * @author Stan Hebben */ -public class GuiCannotRemodify extends GuiScreen{ +public class GuiCannotRemodify extends GuiScreen { + private final String message1; private final String message2; private final String message3; - public GuiCannotRemodify(String message1, String message2, String message3){ + public GuiCannotRemodify(String message1, String message2, String message3) { this.message1 = message1; this.message2 = message2; this.message3 = message3; } @Override - public void initGui(){ + public void initGui() { this.buttonList.clear(); this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120 + 12, "Close")); } @Override - public void drawScreen(int par1, int par2, float par3){ + public void drawScreen(int par1, int par2, float par3) { this.drawDefaultBackground(); this.drawCenteredString(this.fontRendererObj, message1, this.width / 2, this.height / 2 - 40, 11184810); this.drawCenteredString(this.fontRendererObj, message2, this.width / 2, this.height / 2 - 20, 11184810); - this.drawCenteredString(this.fontRendererObj, message3, this.width / 2, this.height / 2 - 0, 11184810); + this.drawCenteredString(this.fontRendererObj, message3, this.width / 2, this.height / 2, 11184810); super.drawScreen(par1, par2, par3); } @Override - protected void actionPerformed(GuiButton par1GuiButton){ - if(par1GuiButton.id == 0){ + protected void actionPerformed(GuiButton par1GuiButton) { + if(par1GuiButton.id == 0) { System.exit(0); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MCPlatformFunctions.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MCPlatformFunctions.java index 0ede039..0762711 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MCPlatformFunctions.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MCPlatformFunctions.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102; import minetweaker.IPlatformFunctions; @@ -20,24 +14,25 @@ import static minetweaker.mc1102.MineTweakerMod.NETWORK; /** * @author Stan */ -public class MCPlatformFunctions implements IPlatformFunctions{ +public class MCPlatformFunctions implements IPlatformFunctions { + public static final MCPlatformFunctions INSTANCE = new MCPlatformFunctions(); - private MCPlatformFunctions(){ + private MCPlatformFunctions() { } @Override - public IChatMessage getMessage(String message){ + public IChatMessage getMessage(String message) { return new MCChatMessage(message); } @Override - public void distributeScripts(byte[] data){ + public void distributeScripts(byte[] data) { NETWORK.sendToAll(new MineTweakerLoadScriptsPacket(data)); } @Override - public IItemDefinition getItemDefinition(int id){ + public IItemDefinition getItemDefinition(int id) { Item item = Item.getItemById(id); if(item == null) return null; diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java index ab0d508..c8625da 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java @@ -1,57 +1,40 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102; -import minetweaker.MineTweakerAPI; -import minetweaker.MineTweakerImplementationAPI; +import minetweaker.*; import minetweaker.annotations.BracketHandler; -import minetweaker.api.logger.FileLogger; -import minetweaker.mc1102.brackets.ItemBracketHandler; -import minetweaker.mc1102.brackets.LiquidBracketHandler; -import minetweaker.mc1102.brackets.OreBracketHandler; +import minetweaker.api.item.IItemStack; +import minetweaker.api.minecraft.MineTweakerMC; +import minetweaker.mc1102.brackets.*; import minetweaker.mc1102.client.MCClient; import minetweaker.mc1102.formatting.MCFormatter; -import minetweaker.mc1102.furnace.FuelTweaker; -import minetweaker.mc1102.furnace.MCFurnaceManager; +import minetweaker.mc1102.furnace.*; import minetweaker.mc1102.game.MCGame; +import minetweaker.mc1102.logger.MCLogger; import minetweaker.mc1102.mods.MCLoadedMods; import minetweaker.mc1102.network.*; import minetweaker.mc1102.oredict.MCOreDict; import minetweaker.mc1102.recipes.MCRecipeManager; import minetweaker.mc1102.server.MCServer; -import minetweaker.mc1102.util.MineTweakerHacks; -import minetweaker.mc1102.util.MineTweakerPlatformUtils; +import minetweaker.mc1102.util.*; import minetweaker.mc1102.vanilla.MCVanilla; -import minetweaker.runtime.GlobalRegistry; -import minetweaker.runtime.IScriptProvider; -import minetweaker.runtime.providers.ScriptProviderCascade; -import minetweaker.runtime.providers.ScriptProviderCustom; -import minetweaker.runtime.providers.ScriptProviderDirectory; +import minetweaker.runtime.*; +import minetweaker.runtime.providers.*; +import net.minecraft.item.crafting.*; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.FMLCommonHandler; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.*; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenExpansion; +import stanhebben.zenscript.annotations.*; import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import static minetweaker.MineTweakerAPI.registerClass; +import java.lang.reflect.Field; +import java.util.*; /** * Main mod class. Performs some general logic, initialization of the API and @@ -59,35 +42,35 @@ import static minetweaker.MineTweakerAPI.registerClass; * * @author Stan Hebben */ -@Mod(modid = MineTweakerMod.MODID, version = "3.0.13") +@Mod(modid = MineTweakerMod.MODID, version = "3.0.26", name = MineTweakerMod.NAME, dependencies = "after:JEI@[3.14.2.398,)") public class MineTweakerMod { + public static final String MODID = "MineTweaker3"; + public static final String NAME = "MineTweaker3"; public static final String MCVERSION = "1.10.2"; - + public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MODID); - + private static final String[] REGISTRIES = {"minetweaker.mods.jei.ClassRegistry", "minetweaker.mods.ic2.ClassRegistry"}; private static final String[] REGISTRY_DESCRIPTIONS = {"JEI mod support", "IC2 mod support"}; public static MinecraftServer server; @Mod.Instance(MODID) public static MineTweakerMod INSTANCE; - + static { NETWORK.registerMessage(MineTweakerLoadScriptsHandler.class, MineTweakerLoadScriptsPacket.class, 0, Side.CLIENT); NETWORK.registerMessage(MineTweakerOpenBrowserHandler.class, MineTweakerOpenBrowserPacket.class, 1, Side.CLIENT); NETWORK.registerMessage(MineTweakerCopyClipboardHandler.class, MineTweakerCopyClipboardPacket.class, 2, Side.CLIENT); } - + public final MCRecipeManager recipes; private final IScriptProvider scriptsGlobal; private final ScriptProviderCustom scriptsIMC; - + public MineTweakerMod() { MineTweakerImplementationAPI.init(new MCOreDict(), recipes = new MCRecipeManager(), new MCFurnaceManager(), MCGame.INSTANCE, new MCLoadedMods(), new MCFormatter(), new MCVanilla()); - - MineTweakerImplementationAPI.logger.addLogger(new FileLogger(new File("minetweaker.log"))); + MineTweakerImplementationAPI.logger.addLogger(new MCLogger(new File("minetweaker.log"))); MineTweakerImplementationAPI.platform = MCPlatformFunctions.INSTANCE; - File globalDir = new File("scripts"); if(!globalDir.exists()) globalDir.mkdirs(); @@ -95,115 +78,120 @@ public class MineTweakerMod { scriptsGlobal = new ScriptProviderDirectory(globalDir); MineTweakerImplementationAPI.setScriptProvider(scriptsGlobal); } - + // ########################## // ### FML Event Handlers ### // ########################## - + @EventHandler public void onIMCEvent(FMLInterModComms.IMCEvent event) { - for(final FMLInterModComms.IMCMessage imcMessage : event.getMessages()) { - if(imcMessage.key.equalsIgnoreCase("addMineTweakerScript")) { - if(imcMessage.isStringMessage()) { - scriptsIMC.add(imcMessage.getSender() + "::imc", imcMessage.getStringValue()); - } else if(imcMessage.isNBTMessage()) { - NBTTagCompound message = imcMessage.getNBTValue(); - scriptsIMC.add(imcMessage.getSender() + "::" + message.getString("name"), message.getString("content")); - } + event.getMessages().stream().filter(imcMessage -> imcMessage.key.equalsIgnoreCase("addMineTweakerScript")).forEach(imcMessage -> { + if(imcMessage.isStringMessage()) { + scriptsIMC.add(imcMessage.getSender() + "::imc", imcMessage.getStringValue()); + } else if(imcMessage.isNBTMessage()) { + NBTTagCompound message = imcMessage.getNBTValue(); + scriptsIMC.add(imcMessage.getSender() + "::" + message.getString("name"), message.getString("content")); } - } + }); } - + @EventHandler public void onLoad(FMLPreInitializationEvent ev) { MinecraftForge.EVENT_BUS.register(new ForgeEventHandler()); - FMLCommonHandler.instance().bus().register(new FMLEventHandler()); - List apiClasses = new ArrayList(); - String[] classNames = new String[]{ZenExpansion.class.getCanonicalName(), ZenClass.class.getCanonicalName(), BracketHandler.class.getCanonicalName()}; - for(String name : classNames) { - ev.getAsmData().getAll(name).forEach(clazz -> { - try { - Class asmClass = Class.forName(clazz.getClassName()); - apiClasses.add(asmClass); - } catch(ClassNotFoundException e) { - e.printStackTrace(); - } - }); - } - for(Class cls : apiClasses) { - registerClass(cls); - } - + MinecraftForge.EVENT_BUS.register(new FMLEventHandler()); +// List apiClasses = new ArrayList<>(); +// String[] classNames = new String[]{ZenExpansion.class.getCanonicalName(), ZenClass.class.getCanonicalName(), BracketHandler.class.getCanonicalName()}; +// for(String name : classNames) { +// ev.getAsmData().getAll(name).forEach(clazz -> { +// boolean valid = true; +// try { +// for(ModContainer mod : clazz.getCandidate().getContainedMods()) { +// if(!mod.getName().equals("MineTweaker 3") || !mod.getName().equals("CT-GUI")) { +// valid = false; +// } +// } +// if(valid) { +// Class asmClass = Class.forName(clazz.getClassName()); +// apiClasses.add(asmClass); +// } +// } catch(ClassNotFoundException e) { +// e.printStackTrace(); +// } +// }); +// } +// apiClasses.forEach(i -> { +// System.out.println(">>> " + i.getName()); +// MineTweakerAPI.registerClass(i); +// }); } - + @EventHandler public void onPostInit(FMLPostInitializationEvent ev) { MineTweakerAPI.registerClassRegistry(MineTweakerRegistry.class); - + for(int i = 0; i < REGISTRIES.length; i++) { MineTweakerAPI.registerClassRegistry(REGISTRIES[i], REGISTRY_DESCRIPTIONS[i]); } - - FuelTweaker.INSTANCE.register(); - if(Loader.isModLoaded("JEI")) { - try { - Method register = Class.forName("minetweaker.mods.jei.JEI").getMethod("onRegister"); - register.invoke(null); - } catch(NoSuchMethodException e) { - e.printStackTrace(); - } catch(ClassNotFoundException e) { - e.printStackTrace(); - } catch(InvocationTargetException e) { - e.printStackTrace(); - } catch(IllegalAccessException e) { - e.printStackTrace(); - } - } } - + @EventHandler public void onComplete(FMLLoadCompleteEvent ev) { MineTweakerAPI.logInfo("MineTweaker: Building registry"); ItemBracketHandler.rebuildItemRegistry(); LiquidBracketHandler.rebuildLiquidRegistry(); + EntityBracketHandler.rebuildEntityRegistry(); MineTweakerAPI.logInfo("MineTweaker: Sucessfully built item registry"); GlobalRegistry.registerBracketHandler(new ItemBracketHandler()); GlobalRegistry.registerBracketHandler(new LiquidBracketHandler()); GlobalRegistry.registerBracketHandler(new OreBracketHandler()); + GlobalRegistry.registerBracketHandler(new EntityBracketHandler()); } - + @EventHandler public void onServerAboutToStart(FMLServerAboutToStartEvent ev) { - this.server = ev.getServer(); - + server = ev.getServer(); + } - + @EventHandler public void onServerStarting(FMLServerStartingEvent ev) { - this.server = ev.getServer(); + server = ev.getServer(); // starts before loading worlds // perfect place to start MineTweaker! - + MineTweakerImplementationAPI.addMineTweakerCommand("itemrecipes", new String[]{"Logs items that have a crafting table recipe"}, (arguments, player) -> { + List stacks = new ArrayList<>(); + for(IRecipe recipe : CraftingManager.getInstance().getRecipeList()) { + stacks.add(MineTweakerMC.getIItemStack(recipe.getRecipeOutput())); + } + for(IItemStack stack : stacks) { + if(stack != null) + MineTweakerAPI.logCommand(stack.toString()); + } + player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir"); + + }); if(MineTweakerPlatformUtils.isClient()) { MineTweakerAPI.client = new MCClient(); } - + File scriptsDir = new File(MineTweakerHacks.getWorldDirectory(ev.getServer()), "scripts"); if(!scriptsDir.exists()) { scriptsDir.mkdir(); } - + IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir); IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal, scriptsLocal); - + MineTweakerImplementationAPI.setScriptProvider(cascaded); MineTweakerImplementationAPI.onServerStart(new MCServer(ev.getServer())); } - + @EventHandler public void onServerStopped(FMLServerStoppedEvent ev) { MineTweakerImplementationAPI.onServerStop(); MineTweakerImplementationAPI.setScriptProvider(scriptsGlobal); - this.server = null; + MineTweakerAPI.logInfo("Server stopping, Scripts are being rolled back!"); + MineTweakerAPI.tweaker.rollback(); + server = null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerRegistry.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerRegistry.java index 8c7b0ae..db40ea1 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerRegistry.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerRegistry.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102; import java.util.List; @@ -11,8 +5,9 @@ import java.util.List; /** * @author Stan */ -public class MineTweakerRegistry{ - public static void getClasses(List classes){ +public class MineTweakerRegistry { + + public static void getClasses(List classes) { // method stub, actual content is generated by build process } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetBlockHardnessAction.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetBlockHardnessAction.java index cbf02cc..f0f78f9 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetBlockHardnessAction.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetBlockHardnessAction.java @@ -1,13 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.actions; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -15,69 +8,69 @@ import net.minecraft.util.ResourceLocation; /** * @author Jared */ -public class SetBlockHardnessAction implements IUndoableAction{ - +public class SetBlockHardnessAction implements IUndoableAction { + private final ItemStack stack; private final float hardness; private final float oldHardness; - - public SetBlockHardnessAction(ItemStack stack, float hardness){ + + public SetBlockHardnessAction(ItemStack stack, float hardness) { this.stack = stack; this.hardness = hardness; - this.oldHardness = Block.getBlockFromItem(stack.getItem()).getBlockHardness(null,null, null); + this.oldHardness = Block.getBlockFromItem(stack.getItem()).getBlockHardness(null, null, null); } - - private static void set(ItemStack stack, float hardness){ - if(isBlock(stack)){ + + private static void set(ItemStack stack, float hardness) { + if(isBlock(stack)) { Block block = Block.getBlockFromItem(stack.getItem()); block.setHardness(hardness); - }else{ + } else { MineTweakerAPI.logError("Item is not a block"); } } - - public static boolean isBlock(ItemStack stack){ + + public static boolean isBlock(ItemStack stack) { ResourceLocation name = Block.REGISTRY.getNameForObject(Block.getBlockFromItem(stack.getItem())); return !name.toString().equals("minecraft:air") && Block.REGISTRY.containsKey(name); - + } - + @Override - public void apply(){ - if(isBlock(stack)){ + public void apply() { + if(isBlock(stack)) { set(stack, hardness); } } - + @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } - + @Override - public void undo(){ + public void undo() { if(isBlock(stack)) set(stack, oldHardness); } - + @Override - public String describe(){ - if(isBlock(stack)){ + public String describe() { + if(isBlock(stack)) { return "Setting hardness of " + stack.getDisplayName() + " to " + hardness; } return "Unable to set hardness of " + stack.getDisplayName() + " because it is an Item"; } - + @Override - public String describeUndo(){ - if(isBlock(stack)){ + public String describeUndo() { + if(isBlock(stack)) { return "Reverting hardness of " + stack.getDisplayName() + " to " + oldHardness; } return "Unable to revert hardness of " + stack.getDisplayName() + " because it is an Item"; } - + @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackSizeAction.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackSizeAction.java index 81ca21e..767926a 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackSizeAction.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackSizeAction.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.actions; import minetweaker.IUndoableAction; @@ -12,49 +6,49 @@ import net.minecraft.item.ItemStack; /** * @author Jared */ -public class SetStackSizeAction implements IUndoableAction{ +public class SetStackSizeAction implements IUndoableAction { private final ItemStack stack; private final int size; private final int oldSize; - public SetStackSizeAction(ItemStack stack, int size){ + public SetStackSizeAction(ItemStack stack, int size) { this.stack = stack; this.size = size; this.oldSize = stack.getMaxStackSize(); } - private static void set(ItemStack stack, int size){ + private static void set(ItemStack stack, int size) { stack.getItem().setMaxStackSize(size); } @Override - public void apply(){ + public void apply() { set(stack, size); } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ + public void undo() { set(stack, oldSize); } @Override - public String describe(){ + public String describe() { return "Setting max stack size of " + stack.getDisplayName() + " to " + size; } @Override - public String describeUndo(){ + public String describeUndo() { return "Reverting max stack size of " + stack.getDisplayName() + " to " + oldSize; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackmaxDamageAction.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackmaxDamageAction.java index 5642147..08551ba 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackmaxDamageAction.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetStackmaxDamageAction.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.actions; import minetweaker.IUndoableAction; @@ -12,49 +6,49 @@ import net.minecraft.item.ItemStack; /** * @author Jared */ -public class SetStackmaxDamageAction implements IUndoableAction{ - +public class SetStackmaxDamageAction implements IUndoableAction { + private final ItemStack stack; private final int damage; private final int oldDamage; - - public SetStackmaxDamageAction(ItemStack stack, int damage){ + + public SetStackmaxDamageAction(ItemStack stack, int damage) { this.stack = stack; this.damage = damage; this.oldDamage = stack.getMaxDamage(); } - - private static void set(ItemStack stack, int damage){ + + private static void set(ItemStack stack, int damage) { stack.getItem().setMaxDamage(damage); } - + @Override - public void apply(){ + public void apply() { set(stack, damage); } - + @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } - + @Override - public void undo(){ + public void undo() { set(stack, oldDamage); } - + @Override - public String describe(){ + public String describe() { return "Setting max damage of " + stack.getDisplayName() + " to " + damage; } - + @Override - public String describeUndo(){ + public String describeUndo() { return "Reverting max damage of " + stack.getDisplayName() + " to " + oldDamage; } - + @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetTranslationAction.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetTranslationAction.java index 00cc43e..3014ae4 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetTranslationAction.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/actions/SetTranslationAction.java @@ -1,12 +1,7 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.actions; import minetweaker.IUndoableAction; +import minetweaker.MineTweakerAPI; import minetweaker.mc1102.util.MineTweakerHacks; import net.minecraft.util.text.translation.LanguageMap; @@ -14,57 +9,58 @@ import java.io.ByteArrayInputStream; import java.nio.charset.Charset; /** - * * @author Stan */ public class SetTranslationAction implements IUndoableAction { - private static final LanguageMap INSTANCE = MineTweakerHacks.getStringTranslateInstance(); - private static final Charset UTF8 = Charset.forName("utf-8"); - private final String key; - private final String newValue; - private final String oldValue; + private static final LanguageMap INSTANCE = MineTweakerHacks.getStringTranslateInstance(); + private static final Charset UTF8 = Charset.forName("utf-8"); - public SetTranslationAction(String key, String value) { - this.key = key; - newValue = value; - oldValue = INSTANCE.translateKey(key); - } + private final String key; + private final String newValue; + private final String oldValue; - @Override - public void apply() { - set(key, newValue); - } + public SetTranslationAction(String key, String value) { + this.key = key; + newValue = value; + oldValue = INSTANCE.translateKey(key); + } - @Override - public boolean canUndo() { - return true; - } + private static void set(String key, String value) { + if(value.contains("\\\"")) { + value = value.replace("\\\"", "\""); + } + LanguageMap.inject(new ByteArrayInputStream((key + "=" + value).getBytes(UTF8))); + MineTweakerAPI.getIjeiRecipeRegistry().reloadItemList(); + } - @Override - public void undo() { - set(key, oldValue); - } + @Override + public void apply() { + set(key, newValue); + } - @Override - public String describe() { - return "Translating " + key + " to " + newValue; - } + @Override + public boolean canUndo() { + return true; + } - @Override - public String describeUndo() { - return "Reverting " + key + " to " + oldValue; - } + @Override + public void undo() { + set(key, oldValue); + } - private static void set(String key, String value) { - if (value.contains("\\\"")) { - value = value.replace("\\\"", "\""); - } - INSTANCE.inject(new ByteArrayInputStream((key + "=" + value).getBytes(UTF8))); - } + @Override + public String describe() { + return "Translating " + key + " to " + newValue; + } - @Override - public Object getOverrideKey() { - return null; - } + @Override + public String describeUndo() { + return "Reverting " + key + " to " + oldValue; + } + + @Override + public Object getOverrideKey() { + return null; + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCBlockDefinition.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCBlockDefinition.java index 72ae408..bdc3435 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCBlockDefinition.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCBlockDefinition.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.block; import minetweaker.api.block.IBlockDefinition; @@ -12,24 +6,25 @@ import net.minecraft.block.Block; /** * @author Stan */ -public class MCBlockDefinition implements IBlockDefinition{ +public class MCBlockDefinition implements IBlockDefinition { + private final Block block; - public MCBlockDefinition(Block block){ + public MCBlockDefinition(Block block) { this.block = block; } - public Block getInternalBlock(){ + public Block getInternalBlock() { return block; } @Override - public String getId(){ + public String getId() { return Block.REGISTRY.getNameForObject(block).toString(); } @Override - public String getDisplayName(){ + public String getDisplayName() { return block.getLocalizedName(); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCItemBlock.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCItemBlock.java index ed463d9..d851828 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCItemBlock.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCItemBlock.java @@ -1,46 +1,37 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.block; -import minetweaker.api.block.BlockPatternOr; -import minetweaker.api.block.IBlock; -import minetweaker.api.block.IBlockDefinition; -import minetweaker.api.block.IBlockPattern; +import minetweaker.api.block.*; import minetweaker.api.data.IData; import minetweaker.api.minecraft.MineTweakerMC; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * @author Stan */ -public class MCItemBlock implements IBlock{ +public class MCItemBlock implements IBlock { + private final ItemStack item; - public MCItemBlock(ItemStack item){ + public MCItemBlock(ItemStack item) { this.item = item; } @Override - public IBlockDefinition getDefinition(){ + public IBlockDefinition getDefinition() { return MineTweakerMC.getBlockDefinition(Block.getBlockFromItem(item.getItem())); } @Override - public int getMeta(){ + public int getMeta() { return item.getItemDamage(); } @Override - public IData getTileData(){ + public IData getTileData() { if(item.getTagCompound() == null) return null; @@ -48,22 +39,22 @@ public class MCItemBlock implements IBlock{ } @Override - public String getDisplayName(){ + public String getDisplayName() { return item.getDisplayName(); } @Override - public List getBlocks(){ - return Collections.singletonList(this); + public List getBlocks() { + return Collections.singletonList(this); } @Override - public boolean matches(IBlock block){ + public boolean matches(IBlock block) { return getDefinition() == block.getDefinition() && (getMeta() == OreDictionary.WILDCARD_VALUE || getMeta() == block.getMeta()) && (getTileData() == null || (block.getTileData() != null && block.getTileData().contains(getTileData()))); } @Override - public IBlockPattern or(IBlockPattern pattern){ + public IBlockPattern or(IBlockPattern pattern) { return new BlockPatternOr(this, pattern); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCSpecificBlock.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCSpecificBlock.java index c79dc6f..7f47555 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCSpecificBlock.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCSpecificBlock.java @@ -1,76 +1,67 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.block; -import minetweaker.api.block.BlockPatternOr; -import minetweaker.api.block.IBlock; -import minetweaker.api.block.IBlockDefinition; -import minetweaker.api.block.IBlockPattern; +import minetweaker.api.block.*; import minetweaker.api.data.IData; import minetweaker.api.minecraft.MineTweakerMC; import net.minecraft.block.Block; import net.minecraftforge.oredict.OreDictionary; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * @author Stan */ -public class MCSpecificBlock implements IBlock{ +public class MCSpecificBlock implements IBlock { + private final Block block; private final int meta; - public MCSpecificBlock(Block block, int meta){ + public MCSpecificBlock(Block block, int meta) { this.block = block; this.meta = meta; } - private static String getBlockId(Block block){ + private static String getBlockId(Block block) { return Block.REGISTRY.getNameForObject(block).toString(); } @Override - public IBlockDefinition getDefinition(){ + public IBlockDefinition getDefinition() { return MineTweakerMC.getBlockDefinition(block); } @Override - public int getMeta(){ + public int getMeta() { return meta; } @Override - public IData getTileData(){ + public IData getTileData() { return null; } @Override - public List getBlocks(){ - return Collections.singletonList(this); + public List getBlocks() { + return Collections.singletonList(this); } @Override - public boolean matches(IBlock block){ + public boolean matches(IBlock block) { return block.getDefinition() == getDefinition() && (meta == OreDictionary.WILDCARD_VALUE || block.getMeta() == meta); } @Override - public IBlockPattern or(IBlockPattern pattern){ + public IBlockPattern or(IBlockPattern pattern) { return new BlockPatternOr(this, pattern); } @Override - public String getDisplayName(){ + public String getDisplayName() { return block.getLocalizedName(); } @Override - public String toString(){ + public String toString() { return ""; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCWorldBlock.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCWorldBlock.java index 5bdb64f..716f6d2 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCWorldBlock.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/block/MCWorldBlock.java @@ -1,58 +1,49 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.block; -import minetweaker.api.block.BlockPatternOr; -import minetweaker.api.block.IBlock; -import minetweaker.api.block.IBlockDefinition; -import minetweaker.api.block.IBlockPattern; +import minetweaker.api.block.*; import minetweaker.api.data.IData; import minetweaker.api.minecraft.MineTweakerMC; import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.item.*; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraftforge.oredict.OreDictionary; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * @author Stan */ -public class MCWorldBlock implements IBlock{ +public class MCWorldBlock implements IBlock { + private final IBlockAccess blocks; private final int x; private final int y; private final int z; private final BlockPos pos; - public MCWorldBlock(IBlockAccess blocks, int x, int y, int z){ + + public MCWorldBlock(IBlockAccess blocks, int x, int y, int z) { this.blocks = blocks; this.x = x; this.y = y; this.z = z; - this.pos = new BlockPos(x,y,z); + this.pos = new BlockPos(x, y, z); } @Override - public IBlockDefinition getDefinition(){ + public IBlockDefinition getDefinition() { return MineTweakerMC.getBlockDefinition(blocks.getBlockState(pos).getBlock()); } @Override - public int getMeta(){ + public int getMeta() { return blocks.getBlockState(pos).getBlock().getMetaFromState(blocks.getBlockState(pos)); } @Override - public IData getTileData(){ + public IData getTileData() { TileEntity tileEntity = blocks.getTileEntity(pos); if(tileEntity == null) @@ -64,28 +55,28 @@ public class MCWorldBlock implements IBlock{ } @Override - public String getDisplayName(){ + public String getDisplayName() { Block block = blocks.getBlockState(pos).getBlock(); Item item = Item.getItemFromBlock(block); - if(item != null){ + if(item != null) { return (new ItemStack(item, 1, getMeta())).getDisplayName(); - }else{ + } else { return block.getLocalizedName(); } } @Override - public List getBlocks(){ - return Collections.singletonList(this); + public List getBlocks() { + return Collections.singletonList(this); } @Override - public boolean matches(IBlock block){ + public boolean matches(IBlock block) { return getDefinition() == block.getDefinition() && (getMeta() == OreDictionary.WILDCARD_VALUE || getMeta() == block.getMeta()) && (getTileData() == null || (block.getTileData() != null && block.getTileData().contains(getTileData()))); } @Override - public IBlockPattern or(IBlockPattern pattern){ + public IBlockPattern or(IBlockPattern pattern) { return new BlockPatternOr(this, pattern); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/EntityBracketHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/EntityBracketHandler.java new file mode 100644 index 0000000..e456c41 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/EntityBracketHandler.java @@ -0,0 +1,77 @@ +package minetweaker.mc1102.brackets; + +import minetweaker.*; +import minetweaker.annotations.BracketHandler; +import minetweaker.api.entity.IEntityDefinition; +import stanhebben.zenscript.compiler.IEnvironmentGlobal; +import stanhebben.zenscript.expression.*; +import stanhebben.zenscript.expression.partial.IPartialExpression; +import stanhebben.zenscript.parser.Token; +import stanhebben.zenscript.symbols.IZenSymbol; +import stanhebben.zenscript.type.natives.IJavaMethod; +import stanhebben.zenscript.util.ZenPosition; + +import java.util.*; + +/** + * @author Jared + */ +@BracketHandler(priority = 100) +public class EntityBracketHandler implements IBracketHandler { + + private static final Map entityNames = new HashMap<>(); + private final IJavaMethod method; + + public EntityBracketHandler() { + method = MineTweakerAPI.getJavaMethod(EntityBracketHandler.class, "getEntity", String.class); + } + + @SuppressWarnings("unchecked") + public static void rebuildEntityRegistry() { + entityNames.clear(); + MineTweakerAPI.game.getEntities().forEach(ent -> { + entityNames.put(ent.getName().toLowerCase(), ent); + }); + } + + public static IEntityDefinition getEntity(String name) { + return entityNames.get(name.toLowerCase()); + } + + @Override + public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) { + if(tokens.size() > 2) { + if(tokens.get(0).getValue().equals("entity") && tokens.get(1).getValue().equals(":")) { + return find(environment, tokens, 2, tokens.size()); + } + } + + return null; + } + + private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex) { + StringBuilder valueBuilder = new StringBuilder(); + for(int i = startIndex; i < endIndex; i++) { + Token token = tokens.get(i); + valueBuilder.append(token.getValue()); + } + + return new EntityReferenceSymbol(environment, valueBuilder.toString()); + } + + private class EntityReferenceSymbol implements IZenSymbol { + + private final IEnvironmentGlobal environment; + private final String name; + + public EntityReferenceSymbol(IEnvironmentGlobal environment, String name) { + this.environment = environment; + this.name = name; + } + + @Override + public IPartialExpression instance(ZenPosition position) { + return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name)); + } + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/ItemBracketHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/ItemBracketHandler.java index 912bec6..428a66d 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/ItemBracketHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/ItemBracketHandler.java @@ -1,24 +1,15 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.brackets; -import minetweaker.IBracketHandler; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import minetweaker.annotations.BracketHandler; -import minetweaker.api.item.IItemStack; -import minetweaker.api.item.IngredientAny; -import net.minecraft.item.Item; +import minetweaker.api.item.*; +import net.minecraft.block.Block; +import net.minecraft.item.*; import net.minecraft.util.ResourceLocation; import net.minecraftforge.oredict.OreDictionary; import stanhebben.zenscript.ZenTokener; import stanhebben.zenscript.compiler.IEnvironmentGlobal; -import stanhebben.zenscript.expression.ExpressionCallStatic; -import stanhebben.zenscript.expression.ExpressionInt; -import stanhebben.zenscript.expression.ExpressionString; +import stanhebben.zenscript.expression.*; import stanhebben.zenscript.expression.partial.IPartialExpression; import stanhebben.zenscript.parser.Token; import stanhebben.zenscript.symbols.IZenSymbol; @@ -26,10 +17,7 @@ import stanhebben.zenscript.type.ZenType; import stanhebben.zenscript.type.natives.IJavaMethod; import stanhebben.zenscript.util.ZenPosition; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize; @@ -37,40 +25,58 @@ import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize; * @author Stan */ @BracketHandler(priority = 100) -public class ItemBracketHandler implements IBracketHandler{ - private static final Map itemNames = new HashMap(); +public class ItemBracketHandler implements IBracketHandler { + + private static final Map itemNames = new HashMap<>(); + private static final Map blockNames = new HashMap<>(); + private final IZenSymbol symbolAny; private final IJavaMethod method; - public ItemBracketHandler(){ + public ItemBracketHandler() { symbolAny = MineTweakerAPI.getJavaStaticFieldSymbol(IngredientAny.class, "INSTANCE"); method = MineTweakerAPI.getJavaMethod(ItemBracketHandler.class, "getItem", String.class, int.class); } - + + public static Map getItemNames() { + return itemNames; + } + + public static Map getBlockNames() { + return blockNames; + } + @SuppressWarnings("unchecked") - public static void rebuildItemRegistry(){ + public static void rebuildItemRegistry() { itemNames.clear(); - - for(ResourceLocation itemName : (Set) Item.REGISTRY.getKeys()){ + blockNames.clear(); + for(ResourceLocation itemName : Item.REGISTRY.getKeys()) { String domain = itemName.toString().replace(" ", "").replace("'", ""); itemNames.put(domain, Item.REGISTRY.getObject(itemName)); } + for(ResourceLocation blockName : Block.REGISTRY.getKeys()) { + String domain = blockName.toString().replace(" ", "").replace("'", ""); + blockNames.put(domain, Block.REGISTRY.getObject(blockName)); + } } - - public static IItemStack getItem(String name, int meta){ + + public static IItemStack getItem(String name, int meta) { // Item item = (Item) Item.itemRegistry.getObject(name); Item item = itemNames.get(name); - if(item != null){ + if(item != null) { return getIItemStackWildcardSize(item, meta); - }else{ + } else if(blockNames.containsKey(name)) { + return getIItemStackWildcardSize(new ItemStack(blockNames.get(name), 1, meta)); + } else { return null; } } - + + @Override - public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens){ + public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) { // any symbol - if(tokens.size() == 1 && tokens.get(0).getValue().equals("*")){ + if(tokens.size() == 1 && tokens.get(0).getValue().equals("*")) { return symbolAny; } @@ -82,14 +88,14 @@ public class ItemBracketHandler implements IBracketHandler{ int toIndex = tokens.size(); int meta = 0; - if(tokens.size() > 2){ - if(tokens.get(0).getValue().equals("item") && tokens.get(1).getValue().equals(":")){ + if(tokens.size() > 2) { + if(tokens.get(0).getValue().equals("item") && tokens.get(1).getValue().equals(":")) { fromIndex = 2; } - if(tokens.get(tokens.size() - 1).getType() == ZenTokener.T_INTVALUE && tokens.get(tokens.size() - 2).getValue().equals(":")){ + if(tokens.get(tokens.size() - 1).getType() == ZenTokener.T_INTVALUE && tokens.get(tokens.size() - 2).getValue().equals(":")) { toIndex = tokens.size() - 2; meta = Integer.parseInt(tokens.get(tokens.size() - 1).getValue()); - }else if(tokens.get(tokens.size() - 1).getValue().equals("*") && tokens.get(tokens.size() - 2).getValue().equals(":")){ + } else if(tokens.get(tokens.size() - 1).getValue().equals("*") && tokens.get(tokens.size() - 2).getValue().equals(":")) { toIndex = tokens.size() - 2; meta = OreDictionary.WILDCARD_VALUE; } @@ -97,35 +103,36 @@ public class ItemBracketHandler implements IBracketHandler{ return find(environment, tokens, fromIndex, toIndex, meta); } - - private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex, int meta){ + + private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex, int meta) { StringBuilder valueBuilder = new StringBuilder(); - for(int i = startIndex; i < endIndex; i++){ + for(int i = startIndex; i < endIndex; i++) { Token token = tokens.get(i); valueBuilder.append(token.getValue()); } - + String itemName = valueBuilder.toString(); - if(itemNames.containsKey(itemName)){ + if(itemNames.containsKey(itemName) || blockNames.containsKey(itemName)) { return new ItemReferenceSymbol(environment, itemName, meta); } - + return null; } - private class ItemReferenceSymbol implements IZenSymbol{ + private class ItemReferenceSymbol implements IZenSymbol { + private final IEnvironmentGlobal environment; private final String name; private final int meta; - public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta){ + public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) { this.environment = environment; this.name = name; this.meta = meta; } @Override - public IPartialExpression instance(ZenPosition position){ + public IPartialExpression instance(ZenPosition position) { return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name), new ExpressionInt(position, meta, ZenType.INT)); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/LiquidBracketHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/LiquidBracketHandler.java index a1567c9..92627a2 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/LiquidBracketHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/LiquidBracketHandler.java @@ -5,51 +5,46 @@ import minetweaker.annotations.BracketHandler; import minetweaker.api.liquid.ILiquidStack; import minetweaker.mc1102.liquid.MCLiquidStack; import minetweaker.runtime.GlobalRegistry; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.*; import stanhebben.zenscript.compiler.IEnvironmentGlobal; -import stanhebben.zenscript.expression.ExpressionCallStatic; -import stanhebben.zenscript.expression.ExpressionString; +import stanhebben.zenscript.expression.*; import stanhebben.zenscript.expression.partial.IPartialExpression; import stanhebben.zenscript.parser.Token; import stanhebben.zenscript.symbols.IZenSymbol; -import stanhebben.zenscript.type.natives.IJavaMethod; -import stanhebben.zenscript.type.natives.JavaMethod; +import stanhebben.zenscript.type.natives.*; import stanhebben.zenscript.util.ZenPosition; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Stan */ @BracketHandler -public class LiquidBracketHandler implements IBracketHandler{ - private static final Map fluidNames = new HashMap(); +public class LiquidBracketHandler implements IBracketHandler { + + private static final Map fluidNames = new HashMap<>(); @SuppressWarnings("unchecked") - public static void rebuildLiquidRegistry(){ + public static void rebuildLiquidRegistry() { fluidNames.clear(); - for(String fluidName : FluidRegistry.getRegisteredFluids().keySet()){ + for(String fluidName : FluidRegistry.getRegisteredFluids().keySet()) { fluidNames.put(fluidName.replace(" ", ""), FluidRegistry.getFluid(fluidName)); } } - public static ILiquidStack getLiquid(String name){ + public static ILiquidStack getLiquid(String name) { Fluid fluid = fluidNames.get(name); - if(fluid != null){ + if(fluid != null) { return new MCLiquidStack(new FluidStack(fluid, 1)); - }else{ + } else { return null; } } @Override - public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens){ - if(tokens.size() > 2){ - if(tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")){ + public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) { + if(tokens.size() > 2) { + if(tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")) { return find(environment, tokens, 2, tokens.size()); } } @@ -57,32 +52,33 @@ public class LiquidBracketHandler implements IBracketHandler{ return null; } - private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex){ + private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex) { StringBuilder valueBuilder = new StringBuilder(); - for(int i = startIndex; i < endIndex; i++){ + for(int i = startIndex; i < endIndex; i++) { Token token = tokens.get(i); valueBuilder.append(token.getValue()); } Fluid fluid = fluidNames.get(valueBuilder.toString()); - if(fluid != null){ + if(fluid != null) { return new LiquidReferenceSymbol(environment, valueBuilder.toString()); } return null; } - private class LiquidReferenceSymbol implements IZenSymbol{ + private class LiquidReferenceSymbol implements IZenSymbol { + private final IEnvironmentGlobal environment; private final String name; - public LiquidReferenceSymbol(IEnvironmentGlobal environment, String name){ + public LiquidReferenceSymbol(IEnvironmentGlobal environment, String name) { this.environment = environment; this.name = name; } @Override - public IPartialExpression instance(ZenPosition position){ + public IPartialExpression instance(ZenPosition position) { IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), LiquidBracketHandler.class, "getLiquid", String.class); return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name)); diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/OreBracketHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/OreBracketHandler.java index 509e4f1..19fdced 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/OreBracketHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brackets/OreBracketHandler.java @@ -1,47 +1,38 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.brackets; -import minetweaker.IBracketHandler; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import minetweaker.annotations.BracketHandler; import minetweaker.api.oredict.IOreDictEntry; import minetweaker.mc1102.oredict.MCOreDictEntry; import minetweaker.runtime.GlobalRegistry; import stanhebben.zenscript.compiler.IEnvironmentGlobal; -import stanhebben.zenscript.expression.ExpressionCallStatic; -import stanhebben.zenscript.expression.ExpressionString; +import stanhebben.zenscript.expression.*; import stanhebben.zenscript.expression.partial.IPartialExpression; import stanhebben.zenscript.parser.Token; import stanhebben.zenscript.symbols.IZenSymbol; -import stanhebben.zenscript.type.natives.IJavaMethod; -import stanhebben.zenscript.type.natives.JavaMethod; +import stanhebben.zenscript.type.natives.*; import stanhebben.zenscript.util.ZenPosition; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.regex.Pattern; /** * @author Stan */ @BracketHandler -public class OreBracketHandler implements IBracketHandler{ - public static IOreDictEntry getOre(String name){ +public class OreBracketHandler implements IBracketHandler { + + public static IOreDictEntry getOre(String name) { return new MCOreDictEntry(name); } - public static List getOreList(String wildcardName){ - List result = new ArrayList(); + public static List getOreList(String wildcardName) { + List result = new ArrayList<>(); Pattern wildcardPattern = Pattern.compile(wildcardName.replaceAll("\\*", ".+")); - for(IOreDictEntry someOreDict : MineTweakerAPI.oreDict.getEntries()){ + for(IOreDictEntry someOreDict : MineTweakerAPI.oreDict.getEntries()) { String oreDictName = someOreDict.getName(); - if(wildcardPattern.matcher(oreDictName).matches()){ + if(wildcardPattern.matcher(oreDictName).matches()) { result.add(getOre(oreDictName)); } } @@ -50,9 +41,9 @@ public class OreBracketHandler implements IBracketHandler{ } @Override - public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens){ - if(tokens.size() > 2){ - if(tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")){ + public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) { + if(tokens.size() > 2) { + if(tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")) { return find(environment, tokens, 2, tokens.size()); } } @@ -60,9 +51,9 @@ public class OreBracketHandler implements IBracketHandler{ return null; } - private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex){ + private IZenSymbol find(IEnvironmentGlobal environment, List tokens, int startIndex, int endIndex) { StringBuilder valueBuilder = new StringBuilder(); - for(int i = startIndex; i < endIndex; i++){ + for(int i = startIndex; i < endIndex; i++) { Token token = tokens.get(i); valueBuilder.append(token.getValue()); } @@ -70,17 +61,18 @@ public class OreBracketHandler implements IBracketHandler{ return new OreReferenceSymbol(environment, valueBuilder.toString()); } - private class OreReferenceSymbol implements IZenSymbol{ + private class OreReferenceSymbol implements IZenSymbol { + private final IEnvironmentGlobal environment; private final String name; - public OreReferenceSymbol(IEnvironmentGlobal environment, String name){ + public OreReferenceSymbol(IEnvironmentGlobal environment, String name) { this.environment = environment; this.name = name; } @Override - public IPartialExpression instance(ZenPosition position){ + public IPartialExpression instance(ZenPosition position) { IJavaMethod method = JavaMethod.get(GlobalRegistry.getTypeRegistry(), OreBracketHandler.class, name.contains("*") ? "getOreList" : "getOre", String.class); return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name)); diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brewing/MCBrewingManager.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brewing/MCBrewingManager.java index 64ee279..eea63a0 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brewing/MCBrewingManager.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/brewing/MCBrewingManager.java @@ -1,32 +1,24 @@ package minetweaker.mc1102.brewing; -import minetweaker.api.item.IItemStack; -import minetweaker.api.item.IngredientItem; -import minetweaker.api.item.IngredientOr; +import minetweaker.api.item.*; import minetweaker.api.recipes.BrewingRecipe; -import minetweaker.api.recipes.IBrewingManager; +import minetweaker.api.recipes.*; import minetweaker.api.recipes.IBrewingRecipe; import minetweaker.mc1102.item.MCItemStack; -import minetweaker.util.ArrayUtil; import net.minecraft.item.ItemStack; -import net.minecraftforge.common.brewing.AbstractBrewingRecipe; -import net.minecraftforge.common.brewing.BrewingOreRecipe; -import net.minecraftforge.common.brewing.BrewingRecipeRegistry; +import net.minecraftforge.common.brewing.*; -import java.util.ArrayList; -import java.util.List; +import java.util.*; -/** - * Created by Jared on 6/3/2016. - */ public class MCBrewingManager implements IBrewingManager { + @Override public List getAll() { - List ret = new ArrayList(); - for (net.minecraftforge.common.brewing.IBrewingRecipe rec : BrewingRecipeRegistry.getRecipes()) { - if (rec instanceof net.minecraftforge.common.brewing.AbstractBrewingRecipe) { + List ret = new ArrayList<>(); + for(net.minecraftforge.common.brewing.IBrewingRecipe rec : BrewingRecipeRegistry.getRecipes()) { + if(rec instanceof net.minecraftforge.common.brewing.AbstractBrewingRecipe) { AbstractBrewingRecipe abs = (AbstractBrewingRecipe) rec; - if (abs instanceof BrewingOreRecipe) { + if(abs instanceof BrewingOreRecipe) { BrewingOreRecipe brew = (BrewingOreRecipe) abs; ret.add(new BrewingRecipe(new MCItemStack(brew.getOutput()), new MCItemStack(brew.getInput()), convert(brew.getIngredient()))); } @@ -34,52 +26,48 @@ public class MCBrewingManager implements IBrewingManager { } return ret; } - + @Override public void remove(IItemStack output) { -// if (output == null) -// throw new IllegalArgumentException("output cannot be null"); -// -// for(net.minecraftforge.common.brewing.IBrewingRecipe recipe : BrewingRecipeRegistry.getRecipes()){ -// if(recipe.is) -// } -// Map smeltingList = FurnaceRecipes.instance().getSmeltingList(); -// -// List toRemove = new ArrayList(); -// List toRemoveValues = new ArrayList(); -// for (Map.Entry entry : smeltingList.entrySet()) { -// if (output.matches(new MCItemStack(entry.getValue())) && (input == null || input.matches(new MCItemStack(entry.getKey())))) { -// toRemove.add(entry.getKey()); -// toRemoveValues.add(entry.getValue()); -// } -// } -// -// if (toRemove.isEmpty()) { -// MineTweakerAPI.logWarning("No furnace recipes for " + output.toString()); -// } else { -// MineTweakerAPI.apply(new MCFurnaceManager.RemoveAction(toRemove, toRemoveValues)); -// } + // if (output == null) + // throw new IllegalArgumentException("output cannot be null"); + // + // for(net.minecraftforge.common.brewing.IBrewingRecipe recipe : BrewingRecipeRegistry.getRecipes()){ + // if(recipe.is) + // } + // Map smeltingList = FurnaceRecipes.instance().getSmeltingList(); + // + // List toRemove = new ArrayList(); + // List toRemoveValues = new ArrayList(); + // for (Map.Entry entry : smeltingList.entrySet()) { + // if (output.matches(new MCItemStack(entry.getValue())) && (input == null || input.matches(new MCItemStack(entry.getKey())))) { + // toRemove.add(entry.getKey()); + // toRemoveValues.add(entry.getValue()); + // } + // } + // + // if (toRemove.isEmpty()) { + // MineTweakerAPI.logWarning("No furnace recipes for " + output.toString()); + // } else { + // MineTweakerAPI.apply(new MCFurnaceManager.RemoveAction(toRemove, toRemoveValues)); + // } } - + @Override public void add(IItemStack output, IItemStack ingredient, IItemStack input) { - + } - + @Override public int remove(IItemStack output, IItemStack ingredients) { return 0; } - + private IngredientOr convert(List ingredients) { IngredientOr ing; - List stacks = new ArrayList(); - - for (ItemStack stack : ingredients) { - stacks.add(new IngredientItem(new MCItemStack(stack), null, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS)); - } + ing = new IngredientOr((IngredientItem[]) ingredients.toArray()); - + return ing; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/chat/MCChatMessage.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/chat/MCChatMessage.java index be26602..d631d21 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/chat/MCChatMessage.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/chat/MCChatMessage.java @@ -1,36 +1,30 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.chat; import minetweaker.api.chat.IChatMessage; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.*; /** * @author Stan */ -public class MCChatMessage implements IChatMessage{ +public class MCChatMessage implements IChatMessage { + private final ITextComponent data; - public MCChatMessage(String message){ + public MCChatMessage(String message) { data = new TextComponentString(message); } - public MCChatMessage(ITextComponent data){ + public MCChatMessage(ITextComponent data) { this.data = data; } @Override - public IChatMessage add(IChatMessage other){ + public IChatMessage add(IChatMessage other) { return new MCChatMessage(data.appendSibling((ITextComponent) other.getInternal())); } @Override - public Object getInternal(){ + public Object getInternal() { return data; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/client/MCClient.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/client/MCClient.java index ebbc875..8635f77 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/client/MCClient.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/client/MCClient.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.client; import minetweaker.api.client.IClient; @@ -15,14 +9,15 @@ import net.minecraftforge.fml.client.FMLClientHandler; /** * @author Stan */ -public class MCClient implements IClient{ +public class MCClient implements IClient { + @Override - public IPlayer getPlayer(){ - return MineTweakerMC.getIPlayer(Minecraft.getMinecraft().thePlayer); + public IPlayer getPlayer() { + return MineTweakerMC.getIPlayer(Minecraft.getMinecraft().player); } @Override - public String getLanguage(){ + public String getLanguage() { return FMLClientHandler.instance().getCurrentLanguage(); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTConverter.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTConverter.java index 878b169..e9d0b7f 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTConverter.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTConverter.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.data; import minetweaker.api.data.*; @@ -11,25 +5,27 @@ import minetweaker.mc1102.util.MineTweakerHacks; import net.minecraft.nbt.*; import java.util.*; +import java.util.stream.Collectors; /** * @author Stan */ -public class NBTConverter implements IDataConverter{ +public class NBTConverter implements IDataConverter { + private static final NBTConverter INSTANCE = new NBTConverter(); - public NBTConverter(){ + public NBTConverter() { } - public static NBTBase from(IData data){ + public static NBTBase from(IData data) { return data.convert(INSTANCE); } - public static IData from(NBTBase nbt, boolean immutable){ + public static IData from(NBTBase nbt, boolean immutable) { if(nbt == null) return null; - switch(nbt.getId()){ + switch(nbt.getId()) { case 1: // byte return new DataByte(((NBTPrimitive) nbt).getByte()); case 2: // short @@ -46,18 +42,16 @@ public class NBTConverter implements IDataConverter{ return new DataByteArray(((NBTTagByteArray) nbt).getByteArray(), immutable); case 8: // string return new DataString(((NBTTagString) nbt).getString()); - case 9:{ // list - List values = new ArrayList(); + case 9: { // list + List values = new ArrayList<>(); List original = MineTweakerHacks.getTagList((NBTTagList) nbt); - for(NBTBase value : original){ - values.add(from(value, immutable)); - } + values.addAll(original.stream().map(value -> from(value, immutable)).collect(Collectors.toList())); return new DataList(values, immutable); } - case 10:{ // compound - Map values = new HashMap(); + case 10: { // compound + Map values = new HashMap<>(); NBTTagCompound original = (NBTTagCompound) nbt; - for(String key : (Set) original.getKeySet()){ + for(String key : original.getKeySet()) { values.put(key, from(original.getTag(key), immutable)); } return new DataMap(values, immutable); @@ -69,76 +63,76 @@ public class NBTConverter implements IDataConverter{ } } - public static void updateMap(NBTTagCompound nbt, IData data){ + public static void updateMap(NBTTagCompound nbt, IData data) { NBTUpdater updater = new NBTUpdater(nbt); data.convert(updater); } @Override - public NBTBase fromBool(boolean value){ + public NBTBase fromBool(boolean value) { return new NBTTagInt(value ? 1 : 0); } @Override - public NBTBase fromByte(byte value){ + public NBTBase fromByte(byte value) { return new NBTTagByte(value); } @Override - public NBTBase fromShort(short value){ + public NBTBase fromShort(short value) { return new NBTTagShort(value); } @Override - public NBTBase fromInt(int value){ + public NBTBase fromInt(int value) { return new NBTTagInt(value); } @Override - public NBTBase fromLong(long value){ + public NBTBase fromLong(long value) { return new NBTTagLong(value); } @Override - public NBTBase fromFloat(float value){ + public NBTBase fromFloat(float value) { return new NBTTagFloat(value); } @Override - public NBTBase fromDouble(double value){ + public NBTBase fromDouble(double value) { return new NBTTagDouble(value); } @Override - public NBTBase fromString(String value){ + public NBTBase fromString(String value) { return new NBTTagString(value); } @Override - public NBTBase fromList(List values){ + public NBTBase fromList(List values) { NBTTagList result = new NBTTagList(); - for(IData value : values){ + for(IData value : values) { result.appendTag(from(value)); } return result; } @Override - public NBTBase fromMap(Map values){ + public NBTBase fromMap(Map values) { NBTTagCompound result = new NBTTagCompound(); - for(Map.Entry entry : values.entrySet()){ + for(Map.Entry entry : values.entrySet()) { result.setTag(entry.getKey(), from(entry.getValue())); } return result; } @Override - public NBTBase fromByteArray(byte[] value){ + public NBTBase fromByteArray(byte[] value) { return new NBTTagByteArray(value); } @Override - public NBTBase fromIntArray(int[] value){ + public NBTBase fromIntArray(int[] value) { return new NBTTagIntArray(value); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTUpdater.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTUpdater.java index 7a8cf60..5773e1e 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTUpdater.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/data/NBTUpdater.java @@ -1,43 +1,35 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.data; -import minetweaker.api.data.IData; -import minetweaker.api.data.IDataConverter; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; +import minetweaker.api.data.*; +import net.minecraft.nbt.*; import java.util.Map; /** * @author Stan */ -public class NBTUpdater extends NBTConverter implements IDataConverter{ +public class NBTUpdater extends NBTConverter implements IDataConverter { + private final NBTTagCompound nbt; - public NBTUpdater(NBTTagCompound compound){ + public NBTUpdater(NBTTagCompound compound) { this.nbt = compound; } @Override - public NBTBase fromMap(Map map){ - for(Map.Entry entry : map.entrySet()){ - if(nbt.hasKey(entry.getKey())){ - if(entry.getValue() == null){ + public NBTBase fromMap(Map map) { + for(Map.Entry entry : map.entrySet()) { + if(nbt.hasKey(entry.getKey())) { + if(entry.getValue() == null) { nbt.removeTag(entry.getKey()); - }else{ - if(nbt.getTag(entry.getKey()).getId() == 10){ - NBTTagCompound tag = (NBTTagCompound) nbt.getTag(entry.getKey()); + } else { + if(nbt.getTag(entry.getKey()).getId() == 10) { nbt.setTag(entry.getKey(), entry.getValue().convert(new NBTUpdater(nbt))); - }else{ + } else { nbt.setTag(entry.getKey(), NBTConverter.from(entry.getValue())); } } - }else if(entry.getValue() != null){ + } else if(entry.getValue() != null) { nbt.setTag(entry.getKey(), from(entry.getValue())); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/entity/MCEntityDefinition.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/entity/MCEntityDefinition.java index 60fdeba..b717f83 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/entity/MCEntityDefinition.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/entity/MCEntityDefinition.java @@ -1,31 +1,67 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.entity; import minetweaker.api.entity.IEntityDefinition; -import net.minecraftforge.fml.common.registry.EntityRegistry; +import minetweaker.api.item.IItemStack; +import net.minecraft.entity.Entity; +import stanhebben.zenscript.value.*; + +import java.util.*; /** * @author Stan */ -public class MCEntityDefinition implements IEntityDefinition{ - private final EntityRegistry.EntityRegistration registration; +public class MCEntityDefinition implements IEntityDefinition { - public MCEntityDefinition(EntityRegistry.EntityRegistration registration){ - this.registration = registration; + private final Class entityClass; + private final String entityName; + + private final Map dropsToAdd = new HashMap<>(); + private final Map dropsToAddPlayerOnly = new HashMap<>(); + private final List dropsToRemove = new ArrayList<>(); + + public MCEntityDefinition(Class entityClass, String entityName) { + this.entityClass = entityClass; + this.entityName = entityName; + } + + + @Override + public String getId() { + return entityClass.getName(); } @Override - public String getId(){ - return registration.getEntityClass().getName(); + public String getName() { + return entityName; } @Override - public String getName(){ - return registration.getEntityName(); + public void addDrop(IItemStack stack, int min, int max) { + dropsToAdd.put(stack, new IntRange(min, max)); + } + + @Override + public void addPlayerOnlyDrop(IItemStack stack, int min, int max) { + dropsToAddPlayerOnly.put(stack, new IntRange(min, max)); + } + + @Override + public void removeDrop(IItemStack stack) { + dropsToRemove.add(stack); + } + + @Override + public Map getDropsToAdd() { + return dropsToAdd; + } + + @Override + public Map getDropsToAddPlayerOnly() { + return dropsToAddPlayerOnly; + } + + @Override + public List getDropsToRemove() { + return dropsToRemove; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedMarkupString.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedMarkupString.java index 44a0a52..26d9fff 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedMarkupString.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedMarkupString.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.formatting; import minetweaker.api.formatting.IFormattedText; @@ -12,32 +6,33 @@ import net.minecraft.util.text.TextFormatting; /** * @author Stan */ -public class FormattedMarkupString implements IMCFormattedString{ +public class FormattedMarkupString implements IMCFormattedString { + private final TextFormatting markup; private final IMCFormattedString contents; - public FormattedMarkupString(TextFormatting markup, IMCFormattedString contents){ + public FormattedMarkupString(TextFormatting markup, IMCFormattedString contents) { this.markup = markup; this.contents = contents; } @Override - public String getTooltipString(){ + public String getTooltipString() { return markup + contents.getTooltipString(markup.toString()); } @Override - public String getTooltipString(String context){ + public String getTooltipString(String context) { return markup + contents.getTooltipString(context + markup); } @Override - public IFormattedText add(IFormattedText other){ + public IFormattedText add(IFormattedText other) { return cat(other); } @Override - public IFormattedText cat(IFormattedText other){ + public IFormattedText cat(IFormattedText other) { return new FormattedStringJoin(this, (IMCFormattedString) other); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedString.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedString.java index 58cdef0..0f55128 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedString.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedString.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.formatting; import minetweaker.api.formatting.IFormattedText; @@ -11,30 +5,31 @@ import minetweaker.api.formatting.IFormattedText; /** * @author Stan */ -public class FormattedString implements IMCFormattedString{ +public class FormattedString implements IMCFormattedString { + private final String value; - public FormattedString(String value){ + public FormattedString(String value) { this.value = value; } @Override - public String getTooltipString(){ + public String getTooltipString() { return value; } @Override - public String getTooltipString(String context){ + public String getTooltipString(String context) { return value; } @Override - public IFormattedText add(IFormattedText other){ + public IFormattedText add(IFormattedText other) { return cat(other); } @Override - public IFormattedText cat(IFormattedText other){ + public IFormattedText cat(IFormattedText other) { return new FormattedStringJoin(this, (IMCFormattedString) other); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedStringJoin.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedStringJoin.java index 1cac5e8..58eb7d1 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedStringJoin.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/FormattedStringJoin.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.formatting; import minetweaker.api.formatting.IFormattedText; @@ -14,35 +8,36 @@ import java.util.Arrays; /** * @author Stan */ -public class FormattedStringJoin implements IMCFormattedString{ +public class FormattedStringJoin implements IMCFormattedString { + private final IMCFormattedString[] values; - public FormattedStringJoin(IMCFormattedString first, IMCFormattedString second){ + public FormattedStringJoin(IMCFormattedString first, IMCFormattedString second) { values = new IMCFormattedString[]{first, second}; } - public FormattedStringJoin(IMCFormattedString[] values){ + public FormattedStringJoin(IMCFormattedString[] values) { this.values = values; } @Override - public String getTooltipString(){ + public String getTooltipString() { StringBuilder result = new StringBuilder(); - for(IMCFormattedString value : values){ + for(IMCFormattedString value : values) { result.append(value.getTooltipString()); } return result.toString(); } @Override - public String getTooltipString(String context){ + public String getTooltipString(String context) { boolean first = true; StringBuilder result = new StringBuilder(); - for(IMCFormattedString value : values){ - if(first){ + for(IMCFormattedString value : values) { + if(first) { first = false; - }else{ + } else { result.append(context); } @@ -54,12 +49,12 @@ public class FormattedStringJoin implements IMCFormattedString{ } @Override - public IFormattedText add(IFormattedText other){ + public IFormattedText add(IFormattedText other) { return cat(other); } @Override - public IFormattedText cat(IFormattedText other){ + public IFormattedText cat(IFormattedText other) { IMCFormattedString[] newValues = Arrays.copyOf(values, values.length + 1); newValues[values.length] = (IMCFormattedString) other; return new FormattedStringJoin(newValues); diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/IMCFormattedString.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/IMCFormattedString.java index 2eb5196..f7e750d 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/IMCFormattedString.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/IMCFormattedString.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.formatting; import minetweaker.api.formatting.IFormattedText; @@ -11,7 +5,8 @@ import minetweaker.api.formatting.IFormattedText; /** * @author Stan */ -public interface IMCFormattedString extends IFormattedText{ +public interface IMCFormattedString extends IFormattedText { + String getTooltipString(); String getTooltipString(String context); diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/MCFormatter.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/MCFormatter.java index 535532c..8e6a8a3 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/MCFormatter.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/formatting/MCFormatter.java @@ -1,127 +1,120 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.formatting; -import minetweaker.api.formatting.IFormattedText; -import minetweaker.api.formatting.IFormatter; +import minetweaker.api.formatting.*; import net.minecraft.util.text.TextFormatting; /** * @author Stan */ -public class MCFormatter implements IFormatter{ +public class MCFormatter implements IFormatter { @Override - public IFormattedText string(String text){ + public IFormattedText string(String text) { return new FormattedString(text); } @Override - public IFormattedText black(IFormattedText text){ + public IFormattedText black(IFormattedText text) { return new FormattedMarkupString(TextFormatting.BLACK, (IMCFormattedString) text); } @Override - public IFormattedText darkBlue(IFormattedText text){ + public IFormattedText darkBlue(IFormattedText text) { return new FormattedMarkupString(TextFormatting.DARK_BLUE, (IMCFormattedString) text); } @Override - public IFormattedText darkGreen(IFormattedText text){ + public IFormattedText darkGreen(IFormattedText text) { return new FormattedMarkupString(TextFormatting.DARK_GREEN, (IMCFormattedString) text); } @Override - public IFormattedText darkAqua(IFormattedText text){ + public IFormattedText darkAqua(IFormattedText text) { return new FormattedMarkupString(TextFormatting.DARK_AQUA, (IMCFormattedString) text); } @Override - public IFormattedText darkRed(IFormattedText text){ + public IFormattedText darkRed(IFormattedText text) { return new FormattedMarkupString(TextFormatting.DARK_RED, (IMCFormattedString) text); } @Override - public IFormattedText darkPurple(IFormattedText text){ + public IFormattedText darkPurple(IFormattedText text) { return new FormattedMarkupString(TextFormatting.DARK_PURPLE, (IMCFormattedString) text); } @Override - public IFormattedText gold(IFormattedText text){ + public IFormattedText gold(IFormattedText text) { return new FormattedMarkupString(TextFormatting.GOLD, (IMCFormattedString) text); } @Override - public IFormattedText gray(IFormattedText text){ + public IFormattedText gray(IFormattedText text) { return new FormattedMarkupString(TextFormatting.GRAY, (IMCFormattedString) text); } @Override - public IFormattedText darkGray(IFormattedText text){ + public IFormattedText darkGray(IFormattedText text) { return new FormattedMarkupString(TextFormatting.DARK_GRAY, (IMCFormattedString) text); } @Override - public IFormattedText blue(IFormattedText text){ + public IFormattedText blue(IFormattedText text) { return new FormattedMarkupString(TextFormatting.BLUE, (IMCFormattedString) text); } @Override - public IFormattedText green(IFormattedText text){ + public IFormattedText green(IFormattedText text) { return new FormattedMarkupString(TextFormatting.GREEN, (IMCFormattedString) text); } @Override - public IFormattedText aqua(IFormattedText text){ + public IFormattedText aqua(IFormattedText text) { return new FormattedMarkupString(TextFormatting.AQUA, (IMCFormattedString) text); } @Override - public IFormattedText red(IFormattedText text){ + public IFormattedText red(IFormattedText text) { return new FormattedMarkupString(TextFormatting.RED, (IMCFormattedString) text); } @Override - public IFormattedText lightPurple(IFormattedText text){ + public IFormattedText lightPurple(IFormattedText text) { return new FormattedMarkupString(TextFormatting.LIGHT_PURPLE, (IMCFormattedString) text); } @Override - public IFormattedText yellow(IFormattedText text){ + public IFormattedText yellow(IFormattedText text) { return new FormattedMarkupString(TextFormatting.YELLOW, (IMCFormattedString) text); } @Override - public IFormattedText white(IFormattedText text){ + public IFormattedText white(IFormattedText text) { return new FormattedMarkupString(TextFormatting.WHITE, (IMCFormattedString) text); } @Override - public IFormattedText obfuscated(IFormattedText text){ + public IFormattedText obfuscated(IFormattedText text) { return new FormattedMarkupString(TextFormatting.OBFUSCATED, (IMCFormattedString) text); } @Override - public IFormattedText bold(IFormattedText text){ + public IFormattedText bold(IFormattedText text) { return new FormattedMarkupString(TextFormatting.BOLD, (IMCFormattedString) text); } @Override - public IFormattedText strikethrough(IFormattedText text){ + public IFormattedText strikethrough(IFormattedText text) { return new FormattedMarkupString(TextFormatting.STRIKETHROUGH, (IMCFormattedString) text); } @Override - public IFormattedText underline(IFormattedText text){ + public IFormattedText underline(IFormattedText text) { return new FormattedMarkupString(TextFormatting.UNDERLINE, (IMCFormattedString) text); } @Override - public IFormattedText italic(IFormattedText text){ + public IFormattedText italic(IFormattedText text) { return new FormattedMarkupString(TextFormatting.ITALIC, (IMCFormattedString) text); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/FuelTweaker.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/FuelTweaker.java index 9e35f4b..3c1cd51 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/FuelTweaker.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/FuelTweaker.java @@ -1,91 +1,85 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.furnace; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; import minetweaker.api.minecraft.MineTweakerMC; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.item.*; import net.minecraftforge.fml.common.IFuelHandler; import net.minecraftforge.fml.common.registry.GameRegistry; import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; -public class FuelTweaker{ +public class FuelTweaker { + public static final FuelTweaker INSTANCE = new FuelTweaker(); - private final HashMap> quickList = new HashMap>(); + private final HashMap> quickList = new HashMap<>(); private List original; - - private FuelTweaker(){ + + private FuelTweaker() { } - - public void register(){ - try{ + + public void register() { + try { Field fuelHandlers = GameRegistry.class.getDeclaredField("fuelHandlers"); fuelHandlers.setAccessible(true); original = (List) fuelHandlers.get(null); - List modified = new ArrayList(); + List modified = new ArrayList<>(); modified.add(new OverridingFuelHandler()); fuelHandlers.set(null, modified); - }catch(NoSuchFieldException ex){ + } catch(NoSuchFieldException ex) { System.out.println("[MineTweaker] Error: could not get GameRegistry fuel handlers field. Cannot use custom fuel values."); - }catch(SecurityException ex){ - System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values."); - }catch(IllegalAccessException ex){ + } catch(SecurityException | IllegalAccessException ex) { System.out.println("[MineTweaker] Error: could not alter GameRegistry fuel handlers field. Cannot use custom fuel values."); } } - - public void addFuelPattern(SetFuelPattern pattern){ + + public void addFuelPattern(SetFuelPattern pattern) { List items = pattern.getPattern().getItems(); - if(items == null){ + if(items == null) { MineTweakerAPI.logError("Cannot set fuel for <*>"); return; } - - for(IItemStack item : pattern.getPattern().getItems()){ + + for(IItemStack item : pattern.getPattern().getItems()) { ItemStack itemStack = MineTweakerMC.getItemStack(item); Item mcItem = itemStack.getItem(); - if(!quickList.containsKey(mcItem)){ - quickList.put(mcItem, new ArrayList()); + if(!quickList.containsKey(mcItem)) { + quickList.put(mcItem, new ArrayList<>()); } quickList.get(mcItem).add(pattern); } + + MineTweakerAPI.getIjeiRecipeRegistry().addFuel(Arrays.asList(MineTweakerMC.getItemStacks(pattern.getPattern().getItems())), pattern.getValue()); } - - public void removeFuelPattern(SetFuelPattern pattern){ - for(IItemStack item : pattern.getPattern().getItems()){ + + public void removeFuelPattern(SetFuelPattern pattern) { + for(IItemStack item : pattern.getPattern().getItems()) { ItemStack itemStack = MineTweakerMC.getItemStack(item); Item mcItem = itemStack.getItem(); - if(quickList.containsKey(mcItem)){ + if(quickList.containsKey(mcItem)) { quickList.get(mcItem).remove(pattern); } + MineTweakerAPI.getIjeiRecipeRegistry().removeFuel(itemStack); } } - - private class OverridingFuelHandler implements IFuelHandler{ + + private class OverridingFuelHandler implements IFuelHandler { + @Override - public int getBurnTime(ItemStack fuel){ - if(quickList.containsKey(fuel.getItem())){ + public int getBurnTime(ItemStack fuel) { + if(quickList.containsKey(fuel.getItem())) { IItemStack stack = MineTweakerMC.getIItemStack(fuel); - - for(SetFuelPattern override : quickList.get(fuel.getItem())){ - if(override.getPattern().matches(stack)){ + + for(SetFuelPattern override : quickList.get(fuel.getItem())) { + if(override.getPattern().matches(stack)) { return override.getValue(); } } } - + int max = 0; - for(IFuelHandler handler : original){ + for(IFuelHandler handler : original) { max = Math.max(max, handler.getBurnTime(fuel)); } return max; diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/MCFurnaceManager.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/MCFurnaceManager.java index 561ed62..155db75 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/MCFurnaceManager.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/MCFurnaceManager.java @@ -1,223 +1,227 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.furnace; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import minetweaker.api.recipes.FurnaceRecipe; -import minetweaker.api.recipes.IFurnaceManager; -import minetweaker.api.recipes.IFurnaceRecipe; +import minetweaker.*; +import minetweaker.api.item.*; +import minetweaker.api.recipes.*; import minetweaker.mc1102.item.MCItemStack; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraftforge.fml.common.registry.GameRegistry; import stanhebben.zenscript.annotations.Optional; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; +import static minetweaker.api.minecraft.MineTweakerMC.*; /** * @author Stan */ -public class MCFurnaceManager implements IFurnaceManager{ - public MCFurnaceManager(){ - +public class MCFurnaceManager implements IFurnaceManager { + + public MCFurnaceManager() { + } - + @Override - public void remove(IIngredient output, @Optional IIngredient input){ + public void remove(IIngredient output, @Optional IIngredient input) { if(output == null) throw new IllegalArgumentException("output cannot be null"); - + Map smeltingList = FurnaceRecipes.instance().getSmeltingList(); - - List toRemove = new ArrayList(); - List toRemoveValues = new ArrayList(); - for(Map.Entry entry : smeltingList.entrySet()){ - if(output.matches(new MCItemStack(entry.getValue())) && (input == null || input.matches(new MCItemStack(entry.getKey())))){ - toRemove.add(entry.getKey()); - toRemoveValues.add(entry.getValue()); + + List toRemove = new ArrayList<>(); + List toRemoveValues = new ArrayList<>(); + + if(input == null) { + for(Map.Entry entry : smeltingList.entrySet()) { + if(output.matches(getIItemStack(entry.getValue()))) { + toRemove.add(entry.getKey()); + toRemoveValues.add(entry.getValue()); + } + } + } else { + for(Map.Entry entry : smeltingList.entrySet()) { + if(output.matches(getIItemStack(entry.getValue())) && input.matches(getIItemStack(entry.getKey()))) { + toRemove.add(entry.getKey()); + toRemoveValues.add(entry.getValue()); + } } } - - if(toRemove.isEmpty()){ + if(toRemove.isEmpty()) { MineTweakerAPI.logWarning("No furnace recipes for " + output.toString()); - }else{ + } else { MineTweakerAPI.apply(new RemoveAction(toRemove, toRemoveValues)); } } - + @Override - public void addRecipe(IItemStack output, IIngredient input, @Optional double xp){ + public void addRecipe(IItemStack output, IIngredient input, @Optional double xp) { List items = input.getItems(); - if(items == null){ + if(items == null) { MineTweakerAPI.logError("Cannot turn " + input.toString() + " into a furnace recipe"); } - + ItemStack[] items2 = getItemStacks(items); ItemStack output2 = getItemStack(output); MineTweakerAPI.apply(new AddRecipeAction(input, items2, output2, xp)); } - + @Override - public void setFuel(IIngredient item, int fuel){ + public void setFuel(IIngredient item, int fuel) { MineTweakerAPI.apply(new SetFuelAction(new SetFuelPattern(item, fuel))); } - + @Override - public int getFuel(IItemStack item){ + public int getFuel(IItemStack item) { return GameRegistry.getFuelValue(getItemStack(item)); } - + @Override public List getAll() { - List retList = new ArrayList(); - for(Map.Entry ent : FurnaceRecipes.instance().getSmeltingList().entrySet()){ - retList.add(new FurnaceRecipe(new MCItemStack(ent.getKey()), new MCItemStack(ent.getValue()), FurnaceRecipes.instance().getSmeltingExperience(ent.getValue()))); - } - return retList; + return FurnaceRecipes.instance().getSmeltingList().entrySet().stream().map(ent -> new FurnaceRecipe(new MCItemStack(ent.getKey()), new MCItemStack(ent.getValue()), FurnaceRecipes.instance().getSmeltingExperience(ent.getValue()))).collect(Collectors.toList()); } - + // ###################### // ### Action classes ### // ###################### - - private static class RemoveAction implements IUndoableAction{ + + private static class RemoveAction implements IUndoableAction { + private final List items; private final List values; - - public RemoveAction(List items, List values){ + + public RemoveAction(List items, List values) { this.items = items; this.values = values; } - + @Override - public void apply(){ - for(ItemStack item : items){ + public void apply() { + for(ItemStack item : items) { FurnaceRecipes.instance().getSmeltingList().remove(item); + MineTweakerAPI.getIjeiRecipeRegistry().removeFurnace(item); } + } - + @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } - + @Override - public void undo(){ - for(int i = 0; i < items.size(); i++){ + public void undo() { + for(int i = 0; i < items.size(); i++) { FurnaceRecipes.instance().getSmeltingList().put(items.get(i), values.get(i)); + MineTweakerAPI.getIjeiRecipeRegistry().addFurnace(Arrays.asList(items.toArray()), values.get(i)); } + } - + @Override - public String describe(){ + public String describe() { return "Removing " + items.size() + " furnace recipes"; } - + @Override - public String describeUndo(){ + public String describeUndo() { return "Restoring " + items.size() + " furnace recipes"; } - + @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } - - private static class AddRecipeAction implements IUndoableAction{ + + private static class AddRecipeAction implements IUndoableAction { + private final IIngredient ingredient; private final ItemStack[] input; private final ItemStack output; private final double xp; - - public AddRecipeAction(IIngredient ingredient, ItemStack[] input, ItemStack output, double xp){ + + public AddRecipeAction(IIngredient ingredient, ItemStack[] input, ItemStack output, double xp) { this.ingredient = ingredient; this.input = input; this.output = output; this.xp = xp; } - + @Override - public void apply(){ - for(ItemStack inputStack : input){ + public void apply() { + for(ItemStack inputStack : input) { FurnaceRecipes.instance().addSmeltingRecipe(inputStack, output, (float) xp); } + MineTweakerAPI.getIjeiRecipeRegistry().addFurnace(Arrays.asList(input), output); } - + @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } - + @Override - public void undo(){ - for(ItemStack inputStack : input){ + public void undo() { + for(ItemStack inputStack : input) { FurnaceRecipes.instance().getSmeltingList().remove(inputStack); + System.out.println(">>>removing"); + MineTweakerAPI.getIjeiRecipeRegistry().removeFurnace(inputStack); } } - + @Override - public String describe(){ + public String describe() { return "Adding furnace recipe for " + ingredient; } - + @Override - public String describeUndo(){ + public String describeUndo() { return "Removing furnace recipe for " + ingredient; } - + @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } - - private static class SetFuelAction implements IUndoableAction{ + + private static class SetFuelAction implements IUndoableAction { + private final SetFuelPattern pattern; - - public SetFuelAction(SetFuelPattern pattern){ + + public SetFuelAction(SetFuelPattern pattern) { this.pattern = pattern; } - + @Override - public void apply(){ + public void apply() { FuelTweaker.INSTANCE.addFuelPattern(pattern); } - + @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } - + @Override - public void undo(){ + public void undo() { FuelTweaker.INSTANCE.removeFuelPattern(pattern); } - + @Override - public String describe(){ + public String describe() { return "Setting fuel for " + pattern.getPattern(); } - + @Override - public String describeUndo(){ + public String describeUndo() { return "Removing fuel for " + pattern.getPattern(); } - + @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/SetFuelPattern.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/SetFuelPattern.java index f1dcdeb..336e047 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/SetFuelPattern.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/furnace/SetFuelPattern.java @@ -2,20 +2,21 @@ package minetweaker.mc1102.furnace; import minetweaker.api.item.IIngredient; -public class SetFuelPattern{ +public class SetFuelPattern { + private final IIngredient pattern; private final int value; - - public SetFuelPattern(IIngredient pattern, int value){ + + public SetFuelPattern(IIngredient pattern, int value) { this.pattern = pattern; this.value = value; } - - public IIngredient getPattern(){ + + public IIngredient getPattern() { return pattern; } - - public int getValue(){ + + public int getValue() { return value; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/game/MCGame.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/game/MCGame.java index f9401cc..dd39d32 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/game/MCGame.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/game/MCGame.java @@ -1,13 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.game; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import minetweaker.api.block.IBlockDefinition; import minetweaker.api.entity.IEntityDefinition; import minetweaker.api.game.IGame; @@ -18,20 +11,15 @@ import minetweaker.api.world.IBiome; import minetweaker.mc1102.entity.MCEntityDefinition; import minetweaker.mc1102.item.MCItemDefinition; import minetweaker.mc1102.liquid.MCLiquidDefinition; -import minetweaker.mc1102.util.MineTweakerHacks; -import minetweaker.mc1102.util.MineTweakerPlatformUtils; +import minetweaker.mc1102.util.*; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; +import net.minecraft.entity.EntityList; import net.minecraft.item.Item; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fml.common.registry.EntityRegistry; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; // TODO Find this // import minetweaker.mc1102.GuiCannotRemodify; @@ -39,47 +27,36 @@ import java.util.Set; /** * @author Stan */ -public class MCGame implements IGame{ +public class MCGame implements IGame { + public static final MCGame INSTANCE = new MCGame(); private static final Map TRANSLATIONS = MineTweakerHacks.getTranslations(); + private static final List ENTITY_DEFINITIONS = new ArrayList<>(); private boolean locked = false; - private MCGame(){ + private MCGame() { } @Override - public List getItems(){ - List result = new ArrayList(); - for(ResourceLocation item : (Set) Item.REGISTRY.getKeys()){ - result.add(new MCItemDefinition(item.toString(), Item.REGISTRY.getObject(item))); - } - return result; + public List getItems() { + return Item.REGISTRY.getKeys().stream().map(item -> new MCItemDefinition(item.toString(), Item.REGISTRY.getObject(item))).collect(Collectors.toList()); } @Override - public List getBlocks(){ - List result = new ArrayList(); - for(ResourceLocation block : (Set) Block.REGISTRY.getKeys()){ - result.add(MineTweakerMC.getBlockDefinition(Block.REGISTRY.getObject(block))); - } - - return result; + public List getBlocks() { + return Block.REGISTRY.getKeys().stream().map(block -> MineTweakerMC.getBlockDefinition(Block.REGISTRY.getObject(block))).collect(Collectors.toList()); } @Override - public List getLiquids(){ - List result = new ArrayList(); - for(Map.Entry entry : FluidRegistry.getRegisteredFluids().entrySet()){ - result.add(new MCLiquidDefinition(entry.getValue())); - } - return result; + public List getLiquids() { + return FluidRegistry.getRegisteredFluids().entrySet().stream().map(entry -> new MCLiquidDefinition(entry.getValue())).collect(Collectors.toList()); } @Override - public List getBiomes(){ - List result = new ArrayList(); - for(IBiome biome : MineTweakerMC.biomes){ - if(biome != null){ + public List getBiomes() { + List result = new ArrayList<>(); + for(IBiome biome : MineTweakerMC.biomes) { + if(biome != null) { result.add(biome); } } @@ -87,51 +64,73 @@ public class MCGame implements IGame{ } @Override - public List getEntities(){ - List result = new ArrayList(); - - for(EntityRegistry.EntityRegistration entityRegistration : MineTweakerHacks.getEntityClassRegistrations().values()){ - result.add(new MCEntityDefinition(entityRegistration)); + public List getEntities() { + if(ENTITY_DEFINITIONS.isEmpty()) { + EntityList.CLASS_TO_NAME.forEach((key, val) -> { + ENTITY_DEFINITIONS.add(new MCEntityDefinition(key, val)); + }); } - - return result; + return ENTITY_DEFINITIONS; } @Override - public void setLocalization(String key, String value){ + public IEntityDefinition getEntity(String entityName) { + for(IEntityDefinition ent : getEntities()) { + if(ent.getName().equalsIgnoreCase(entityName)) { + return ent; + } + } + boolean needsReloading = false; + for(String s : EntityList.NAME_TO_CLASS.keySet()) { + if(s.equalsIgnoreCase(entityName)) { + needsReloading = true; + break; + } + } + if(needsReloading) { + ENTITY_DEFINITIONS.clear(); + EntityList.CLASS_TO_NAME.forEach((key, val) -> { + ENTITY_DEFINITIONS.add(new MCEntityDefinition(key, val)); + }); + } + return getEntities().stream().filter(ent -> ent.getName().equals(entityName)).findFirst().orElse(null); + } + + @Override + public void setLocalization(String key, String value) { MineTweakerAPI.apply(new SetTranslation(null, key, value)); } @Override - public void setLocalization(String lang, String key, String value){ + public void setLocalization(String lang, String key, String value) { MineTweakerAPI.apply(new SetTranslation(lang, key, value)); } @Override - public String localize(String key){ + public String localize(String key) { return net.minecraft.util.text.translation.I18n.translateToLocal(key); } @Override - public String localize(String key, String lang){ + public String localize(String key, String lang) { return net.minecraft.util.text.translation.I18n.translateToLocal(key); } @Override - public void lock(){ + public void lock() { locked = true; } @Override - public boolean isLocked(){ + public boolean isLocked() { return locked; } @Override - public void signalLockError(){ + public void signalLockError() { MineTweakerAPI.getLogger().logError("Reload of scripts blocked (script lock)"); - if(Minecraft.isGuiEnabled()){ + if(Minecraft.isGuiEnabled()) { // Commented out due to unresolved import /** * Minecraft.getMinecraft().displayGuiScreen( new GuiCannotRemodify( @@ -151,58 +150,59 @@ public class MCGame implements IGame{ * * @author Joshiejack */ - private static class SetTranslation implements IUndoableAction{ + private static class SetTranslation implements IUndoableAction { + private final String lang; private final String key; private final String text; private String original; private boolean added; - public SetTranslation(String lang, String key, String text){ + public SetTranslation(String lang, String key, String text) { this.lang = lang; this.key = key; this.text = text; } @Override - public void apply(){ - if(lang == null || MineTweakerPlatformUtils.isLanguageActive(lang)){ + public void apply() { + if(lang == null || MineTweakerPlatformUtils.isLanguageActive(lang)) { original = TRANSLATIONS.get(key); TRANSLATIONS.put(key, text); added = true; - }else{ + } else { added = false; } } @Override - public boolean canUndo(){ + public boolean canUndo() { return TRANSLATIONS != null; } @Override - public void undo(){ - if(added){ - if(original == null){ + public void undo() { + if(added) { + if(original == null) { TRANSLATIONS.remove(key); - }else{ + } else { TRANSLATIONS.put(key, original); } } } @Override - public String describe(){ + public String describe() { return "Setting localization for the key: " + key + " to " + text; } @Override - public String describeUndo(){ + public String describeUndo() { return "Setting localization for the key: " + key + " to " + original; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemDefinition.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemDefinition.java index b1dae16..5791583 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemDefinition.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemDefinition.java @@ -1,58 +1,50 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.item; import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IItemDefinition; -import minetweaker.api.item.IItemStack; +import minetweaker.api.item.*; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.oredict.IOreDictEntry; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.item.*; import net.minecraftforge.oredict.OreDictionary; import stanhebben.zenscript.annotations.Optional; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * @author Stan */ -public class MCItemDefinition implements IItemDefinition{ +public class MCItemDefinition implements IItemDefinition { + private final String id; private final Item item; - public MCItemDefinition(String id, Item item){ + public MCItemDefinition(String id, Item item) { this.id = id; this.item = item; } @Override - public String getId(){ + public String getId() { return id; } @Override - public String getName(){ + public String getName() { return item.getUnlocalizedName(); } @Override - public IItemStack makeStack(@Optional int meta){ + public IItemStack makeStack(@Optional int meta) { return MineTweakerMC.getIItemStackWildcardSize(new ItemStack(item, 1, meta)); } @Override - public List getOres(){ - List result = new ArrayList(); + public List getOres() { + List result = new ArrayList<>(); - for(String key : OreDictionary.getOreNames()){ - for(ItemStack is : OreDictionary.getOres(key)){ - if(is.getItem() == item){ + for(String key : OreDictionary.getOreNames()) { + for(ItemStack is : OreDictionary.getOres(key)) { + if(is.getItem() == item) { result.add(MineTweakerAPI.oreDict.get(key)); break; } @@ -67,18 +59,18 @@ public class MCItemDefinition implements IItemDefinition{ // ############################# @Override - public int hashCode(){ + public int hashCode() { int hash = 7; hash = 37 * hash + (this.item != null ? this.item.hashCode() : 0); return hash; } @Override - public boolean equals(Object obj){ - if(obj == null){ + public boolean equals(Object obj) { + if(obj == null) { return false; } - if(getClass() != obj.getClass()){ + if(getClass() != obj.getClass()) { return false; } final MCItemDefinition other = (MCItemDefinition) obj; diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemStack.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemStack.java index 8116f52..94e756d 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemStack.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/item/MCItemStack.java @@ -1,374 +1,359 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.item; import minetweaker.MineTweakerAPI; import minetweaker.api.block.IBlock; -import minetweaker.api.data.DataMap; -import minetweaker.api.data.IData; +import minetweaker.api.data.*; import minetweaker.api.item.*; import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.oredict.IOreDictEntry; import minetweaker.api.player.IPlayer; -import minetweaker.mc1102.actions.SetBlockHardnessAction; -import minetweaker.mc1102.actions.SetStackSizeAction; -import minetweaker.mc1102.actions.SetStackmaxDamageAction; -import minetweaker.mc1102.actions.SetTranslationAction; +import minetweaker.mc1102.actions.*; import minetweaker.mc1102.block.MCItemBlock; import minetweaker.mc1102.data.NBTConverter; import minetweaker.mc1102.liquid.MCLiquidStack; import minetweaker.util.ArrayUtil; import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.item.*; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.*; import net.minecraftforge.fml.relauncher.ReflectionHelper; import net.minecraftforge.oredict.OreDictionary; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * @author Stan */ -public class MCItemStack implements IItemStack{ +public class MCItemStack implements IItemStack { + private final ItemStack stack; private final List items; private IData tag = null; private boolean wildcardSize; - - public MCItemStack(ItemStack itemStack){ + + public MCItemStack(ItemStack itemStack) { if(itemStack == null) throw new IllegalArgumentException("stack cannot be null"); - + stack = itemStack.copy(); - items = Collections.singletonList(this); + items = Collections.singletonList(this); } - - public MCItemStack(ItemStack itemStack, boolean wildcardSize){ + + public MCItemStack(ItemStack itemStack, boolean wildcardSize) { this(itemStack); - + this.wildcardSize = wildcardSize; } - - private MCItemStack(ItemStack itemStack, IData tag){ + + private MCItemStack(ItemStack itemStack, IData tag) { if(itemStack == null) throw new IllegalArgumentException("stack cannot be null"); - + stack = itemStack; - items = Collections.singletonList(this); + items = Collections.singletonList(this); this.tag = tag; } - - private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize){ + + private MCItemStack(ItemStack itemStack, IData tag, boolean wildcardSize) { stack = itemStack; - items = Collections.singletonList(this); + items = Collections.singletonList(this); this.tag = tag; this.wildcardSize = wildcardSize; } - + @Override - public IItemDefinition getDefinition(){ + public IItemDefinition getDefinition() { return new MCItemDefinition(Item.REGISTRY.getNameForObject(stack.getItem()).toString(), stack.getItem()); } - + @Override - public String getName(){ + public String getName() { return stack.getUnlocalizedName(); } - + @Override - public String getDisplayName(){ + public String getDisplayName() { return stack.getDisplayName(); } - + @Override - public void setDisplayName(String name){ + public void setDisplayName(String name) { MineTweakerAPI.apply(new SetTranslationAction(getName() + ".name", name)); } - + @Override - public int getMaxStackSize(){ + public int getMaxStackSize() { return stack.getMaxStackSize(); } - + @Override - public void setMaxStackSize(int size){ + public void setMaxStackSize(int size) { MineTweakerAPI.apply(new SetStackSizeAction((ItemStack) getInternal(), size)); } - + @Override - public float getBlockHardness(){ + public float getBlockHardness() { return ReflectionHelper.getPrivateValue(Block.class, Block.getBlockFromItem(stack.getItem()), "blockHardness"); } - + @Override - public void setBlockHardness(float hardness){ + public void setBlockHardness(float hardness) { MineTweakerAPI.apply(new SetBlockHardnessAction(stack, hardness)); } - + @Override - public int getDamage(){ + public int getDamage() { return stack.getItemDamage(); } - + @Override - public IData getTag(){ - if(tag == null){ - if(stack.getTagCompound() == null){ + public IData getTag() { + if(tag == null) { + if(stack.getTagCompound() == null) { return DataMap.EMPTY; } - + tag = NBTConverter.from(stack.getTagCompound(), true); } return tag; } - + @Override - public int getMaxDamage(){ + public int getMaxDamage() { return stack.getMaxDamage(); } - + @Override - public void setMaxDamage(int damage){ + public void setMaxDamage(int damage) { MineTweakerAPI.apply(new SetStackmaxDamageAction(stack, damage)); } - + @Override - public ILiquidStack getLiquid(){ + public ILiquidStack getLiquid() { FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack); return liquid == null ? null : new MCLiquidStack(liquid); } - + @Override - public IIngredient anyDamage(){ - if(stack.getItem().getHasSubtypes()){ - MineTweakerAPI.logWarning("subitems don't have damaged states"); - return this; - }else{ + public IIngredient anyDamage() { ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, OreDictionary.WILDCARD_VALUE); result.setTagCompound(stack.getTagCompound()); return new MCItemStack(result, tag); - } } - + @Override - public IItemStack withDamage(int damage){ - if(stack.getItem().getHasSubtypes()){ - MineTweakerAPI.logWarning("subitems don't have damaged states"); - return this; - }else{ + public IItemStack withDamage(int damage) { ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, damage); result.setTagCompound(stack.getTagCompound()); return new MCItemStack(result, tag); - } } - + @Override - public IItemStack anyAmount(){ + public IItemStack anyAmount() { ItemStack result = new ItemStack(stack.getItem(), 1, stack.getItemDamage()); result.setTagCompound(stack.getTagCompound()); return new MCItemStack(result, tag, true); } - + @Override - public IItemStack withAmount(int amount){ + public IItemStack withAmount(int amount) { ItemStack result = new ItemStack(stack.getItem(), amount, stack.getItemDamage()); result.setTagCompound(stack.getTagCompound()); return new MCItemStack(result, tag); } - + @Override - public IItemStack withTag(IData tag){ + public IItemStack withTag(IData tag) { ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, stack.getItemDamage()); - if(tag == null){ + if(tag == null) { result.setTagCompound(null); - }else{ + } else { result.setTagCompound((NBTTagCompound) NBTConverter.from(tag)); } return new MCItemStack(result, tag); } - + @Override - public IItemStack updateTag(IData tagUpdate){ - if(tag == null){ - if(stack.getTagCompound() == null){ + public IItemStack withEmptyTag() { + ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, stack.getItemDamage()); + result.setTagCompound(new NBTTagCompound()); + return new MCItemStack(result, NBTConverter.from(new NBTTagCompound(), true)); + } + + @Override + public IItemStack updateTag(IData tagUpdate) { + if(tag == null) { + if(stack.getTagCompound() == null) { return withTag(tagUpdate); } - + tag = NBTConverter.from(stack.getTagCompound(), true); } - + IData updated = tag.update(tagUpdate); return withTag(updated); } - + @Override - public IItemStack removeTag(String tag){ + public IItemStack removeTag(String tag) { ItemStack result = new ItemStack(stack.getItem(), stack.stackSize, stack.getItemDamage()); - - if(tag == null){ + + if(tag == null) { result.setTagCompound(null); - }else{ + } else { result.getTagCompound().removeTag(tag); } IData dataTag = NBTConverter.from(result.getTagCompound(), false); return new MCItemStack(result, dataTag); } - + @Override - public String getMark(){ + public String getMark() { return null; } - + @Override - public int getAmount(){ + public int getAmount() { return stack.stackSize; } - + @Override - public List getItems(){ + public List getItems() { return items; } - + @Override - public List getLiquids(){ + public List getLiquids() { return Collections.emptyList(); } - + @Override - public IItemStack amount(int amount){ + public IItemStack amount(int amount) { return withAmount(amount); } - + @Override - public WeightedItemStack percent(float chance){ + public WeightedItemStack percent(float chance) { return new WeightedItemStack(this, chance * 0.01f); } - + @Override - public WeightedItemStack weight(float chance){ + public WeightedItemStack weight(float chance) { return new WeightedItemStack(this, chance); } - + @Override - public IIngredient transform(IItemTransformer transformer){ + public IIngredient transform(IItemTransformer transformer) { return new IngredientItem(this, null, ArrayUtil.EMPTY_CONDITIONS, new IItemTransformer[]{transformer}); } - + @Override - public IIngredient only(IItemCondition condition){ + public IIngredient only(IItemCondition condition) { return new IngredientItem(this, null, new IItemCondition[]{condition}, ArrayUtil.EMPTY_TRANSFORMERS); } - + @Override - public IIngredient marked(String mark){ + public IIngredient marked(String mark) { return new IngredientItem(this, mark, ArrayUtil.EMPTY_CONDITIONS, ArrayUtil.EMPTY_TRANSFORMERS); } - + @Override - public IIngredient or(IIngredient ingredient){ + public IIngredient or(IIngredient ingredient) { return new IngredientOr(this, ingredient); } - + @Override - public boolean matches(IItemStack item){ + public boolean matches(IItemStack item) { ItemStack internal = getItemStack(item); + if(stack.hasTagCompound()) { + return matchesExact(item); + } return internal != null && stack != null && internal.getItem() == stack.getItem() && (wildcardSize || internal.stackSize >= stack.stackSize) && (stack.getItemDamage() == OreDictionary.WILDCARD_VALUE || stack.getItemDamage() == internal.getItemDamage() || (!stack.getHasSubtypes() && !stack.getItem().isDamageable())); } - + @Override public boolean matchesExact(IItemStack item) { ItemStack internal = getItemStack(item); - if (internal.getTagCompound() != null && stack.getTagCompound() == null) { + if(internal.getTagCompound() != null && stack.getTagCompound() == null) { return false; } - if (internal.getTagCompound() == null && stack.getTagCompound() != null) { + if(internal.getTagCompound() == null && stack.getTagCompound() != null) { return false; } - if (internal.getTagCompound() == null && stack.getTagCompound() == null) { + if(internal.getTagCompound() == null && stack.getTagCompound() == null) { return stack.getItem() == internal.getItem() && (internal.getMetadata() == 32767 || stack.getMetadata() == internal.getMetadata()); } - if (internal.getTagCompound().getKeySet().equals(stack.getTagCompound().getKeySet())) { - for (String s : internal.getTagCompound().getKeySet()) { - if (!internal.getTagCompound().getTag(s).equals(stack.getTagCompound().getTag(s))) { + if(internal.getTagCompound().getKeySet().equals(stack.getTagCompound().getKeySet())) { + for(String s : internal.getTagCompound().getKeySet()) { + if(!internal.getTagCompound().getTag(s).equals(stack.getTagCompound().getTag(s))) { return false; } } } return stack.getItem() == internal.getItem() && (internal.getMetadata() == 32767 || stack.getMetadata() == internal.getMetadata()); } - + @Override - public boolean matches(ILiquidStack liquid){ + public boolean matches(ILiquidStack liquid) { return false; } - + @Override - public boolean contains(IIngredient ingredient){ + public boolean contains(IIngredient ingredient) { List iitems = ingredient.getItems(); - if(iitems == null || iitems.size() != 1) - return false; - return matches(iitems.get(0)); + return !(iitems == null || iitems.size() != 1) && matches(iitems.get(0)); } - + @Override - public IItemStack applyTransform(IItemStack item, IPlayer byPlayer){ + public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) { return item; } - + @Override - public boolean hasTransformers(){ + public boolean hasTransformers() { return false; } - + @Override - public Object getInternal(){ + public Object getInternal() { return stack; } - + @Override - public IBlock asBlock(){ + public IBlock asBlock() { ResourceLocation name = Block.REGISTRY.getNameForObject(Block.getBlockFromItem(stack.getItem())); - if(Block.REGISTRY.containsKey(name)){ + if(Block.REGISTRY.containsKey(name)) { return new MCItemBlock(stack); - }else{ + } else { throw new ClassCastException("This item is not a block"); } } - + @Override - public List getOres(){ - List result = new ArrayList(); - - for(String key : OreDictionary.getOreNames()){ - for(ItemStack is : OreDictionary.getOres(key)){ - if(is.getItem() == stack.getItem() && (is.getItemDamage() == OreDictionary.WILDCARD_VALUE || is.getItemDamage() == stack.getItemDamage())){ + public List getOres() { + List result = new ArrayList<>(); + + for(String key : OreDictionary.getOreNames()) { + for(ItemStack is : OreDictionary.getOres(key)) { + if(is.getItem() == stack.getItem() && (is.getItemDamage() == OreDictionary.WILDCARD_VALUE || is.getItemDamage() == stack.getItemDamage())) { result.add(MineTweakerAPI.oreDict.get(key)); break; } } } - + return result; } - + // ############################# // ### Object implementation ### // ############################# - + @Override - public int hashCode(){ + public int hashCode() { int hash = 7; hash = 41 * hash + stack.getItem().hashCode(); hash = 41 * hash + stack.getItemDamage(); @@ -377,48 +362,42 @@ public class MCItemStack implements IItemStack{ hash = 41 * hash + (this.wildcardSize ? 1 : 0); return hash; } - + @Override - public boolean equals(Object obj){ - if(obj == null){ + public boolean equals(Object obj) { + if(obj == null) { return false; } - if(getClass() != obj.getClass()){ + if(getClass() != obj.getClass()) { return false; } final MCItemStack other = (MCItemStack) obj; - if(this.stack.getItem() != other.stack.getItem()) - return false; - if(this.stack.getItemDamage() != other.stack.getItemDamage()) - return false; - if(this.stack.stackSize != other.stack.stackSize) - return false; - if(this.stack.getTagCompound() != other.stack.getTagCompound() && (this.stack == null || this.stack.equals(other.stack))) - return false; - return this.wildcardSize == other.wildcardSize; + return this.stack.getItem() == other.stack.getItem() && this.stack.getItemDamage() == other.stack.getItemDamage() && this.stack.stackSize == other.stack.stackSize && !(this.stack.getTagCompound() != other.stack.getTagCompound() && (this.stack == null || this.stack.equals(other.stack))) && this.wildcardSize == other.wildcardSize; } - + @Override - public String toString(){ + public String toString() { StringBuilder result = new StringBuilder(); result.append('<'); result.append(Item.REGISTRY.getNameForObject(stack.getItem())); - - if(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE){ + + if(stack.getItemDamage() == OreDictionary.WILDCARD_VALUE) { result.append(":*"); - }else if(stack.getItemDamage() > 0){ + } else if(stack.getItemDamage() > 0) { result.append(':').append(stack.getItemDamage()); } result.append('>'); - - if(stack.getTagCompound() != null){ + + if(stack.getTagCompound() != null) { result.append(".withTag("); result.append(NBTConverter.from(stack.getTagCompound(), wildcardSize).toString()); result.append(")"); } - + if(!wildcardSize && stack.stackSize > 1) { + result.append(" * ").append(stack.stackSize); + } return result.toString(); } - - + + } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidDefinition.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidDefinition.java index 1a2fedf..21d0e8b 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidDefinition.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidDefinition.java @@ -1,104 +1,94 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.liquid; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import minetweaker.api.item.IItemStack; -import minetweaker.api.liquid.ILiquidDefinition; -import minetweaker.api.liquid.ILiquidStack; +import minetweaker.api.liquid.*; import minetweaker.api.minecraft.MineTweakerMC; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.*; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * @author Stan */ -public class MCLiquidDefinition implements ILiquidDefinition{ +public class MCLiquidDefinition implements ILiquidDefinition { + private final Fluid fluid; - public MCLiquidDefinition(Fluid fluid){ + public MCLiquidDefinition(Fluid fluid) { this.fluid = fluid; } @Override - public String getName(){ + public String getName() { return fluid.getName(); } @Override - public String getDisplayName(){ + public String getDisplayName() { return fluid.getLocalizedName(new FluidStack(fluid, 1000)); } @Override - public ILiquidStack asStack(int millibuckets){ + public ILiquidStack asStack(int millibuckets) { return new MCLiquidStack(new FluidStack(fluid, millibuckets)); } @Override - public int getLuminosity(){ + public int getLuminosity() { return fluid.getLuminosity(); } @Override - public void setLuminosity(int value){ + public void setLuminosity(int value) { MineTweakerAPI.apply(new ActionSetLuminosity(value)); } @Override - public int getDensity(){ + public int getDensity() { return fluid.getDensity(); } @Override - public void setDensity(int density){ + public void setDensity(int density) { MineTweakerAPI.apply(new ActionSetDensity(density)); } @Override - public int getTemperature(){ + public int getTemperature() { return fluid.getTemperature(); } @Override - public void setTemperature(int temperature){ + public void setTemperature(int temperature) { MineTweakerAPI.apply(new ActionSetTemperature(temperature)); } @Override - public int getViscosity(){ + public int getViscosity() { return fluid.getViscosity(); } @Override - public void setViscosity(int viscosity){ + public void setViscosity(int viscosity) { MineTweakerAPI.apply(new ActionSetViscosity(viscosity)); } @Override - public boolean isGaseous(){ + public boolean isGaseous() { return fluid.isGaseous(); } @Override - public void setGaseous(boolean gaseous){ + public void setGaseous(boolean gaseous) { MineTweakerAPI.apply(new ActionSetGaseous(gaseous)); } @Override - public List getContainers(){ - List result = new ArrayList(); - for(FluidContainerRegistry.FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()){ - if(data.fluid.getFluid() == fluid){ + public List getContainers() { + List result = new ArrayList<>(); + for(FluidContainerRegistry.FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) { + if(data.fluid.getFluid() == fluid) { result.add(MineTweakerMC.getIItemStack(data.filledContainer)); } } @@ -106,12 +96,12 @@ public class MCLiquidDefinition implements ILiquidDefinition{ } @Override - public void addContainer(IItemStack filled, IItemStack empty, int amount){ + public void addContainer(IItemStack filled, IItemStack empty, int amount) { MineTweakerAPI.apply(new AddContainerAction(filled, empty, amount)); } @Override - public void removeContainer(IItemStack filled){ + public void removeContainer(IItemStack filled) { // MineTweakerAPI.apply(new RemoveContainerAction(filled)); MineTweakerAPI.logError("Cannot remove container items in MineCraft 1.7.X"); } @@ -141,7 +131,7 @@ public class MCLiquidDefinition implements ILiquidDefinition{ */ /* - * private FluidContainerRegistry.FluidContainerData getData(IItemStack + * private FluidContainerRegistry.FluidContainerData getData(IItemStack * filled) { ItemStack filledStack = MineTweakerMC.getItemStack(filled); * return filledContainerMap.get(Arrays.asList(filledStack.itemID, * filledStack.getItemDamage())); } @@ -151,45 +141,46 @@ public class MCLiquidDefinition implements ILiquidDefinition{ // ### Action classes ### // ###################### - private class AddContainerAction implements IUndoableAction{ + private class AddContainerAction implements IUndoableAction { + private final IItemStack filled; private final IItemStack empty; private final int amount; - public AddContainerAction(IItemStack filled, IItemStack empty, int amount){ + public AddContainerAction(IItemStack filled, IItemStack empty, int amount) { this.filled = filled; this.empty = empty; this.amount = amount; } @Override - public void apply(){ + public void apply() { FluidContainerRegistry.registerFluidContainer(new FluidStack(fluid, amount), MineTweakerMC.getItemStack(filled), MineTweakerMC.getItemStack(empty)); } @Override - public boolean canUndo(){ + public boolean canUndo() { return false; // return true; } @Override - public void undo(){ + public void undo() { // removeContainerInner(filled); } @Override - public String describe(){ + public String describe() { return "Adding " + filled.getDisplayName() + " as liquid container for " + fluid.getLocalizedName(new FluidStack(fluid, 1000)); } @Override - public String describeUndo(){ + public String describeUndo() { return "Removing liquid container " + filled; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } @@ -221,202 +212,207 @@ public class MCLiquidDefinition implements ILiquidDefinition{ * @Override public Object getOverrideKey() { return null; } } */ - private class ActionSetLuminosity implements IUndoableAction{ + private class ActionSetLuminosity implements IUndoableAction { + private final int oldValue; private final int newValue; - public ActionSetLuminosity(int newValue){ + public ActionSetLuminosity(int newValue) { oldValue = getLuminosity(); this.newValue = newValue; } @Override - public void apply(){ + public void apply() { fluid.setLuminosity(newValue); } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ + public void undo() { fluid.setLuminosity(oldValue); } @Override - public String describe(){ + public String describe() { return "Setting " + fluid.getName() + " luminosity to " + newValue; } @Override - public String describeUndo(){ + public String describeUndo() { return "Restoring " + fluid.getName() + " luminosity to " + oldValue; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } - private class ActionSetDensity implements IUndoableAction{ + private class ActionSetDensity implements IUndoableAction { + private final int oldValue; private final int newValue; - public ActionSetDensity(int newValue){ + public ActionSetDensity(int newValue) { oldValue = getDensity(); this.newValue = newValue; } @Override - public void apply(){ + public void apply() { fluid.setDensity(newValue); } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ + public void undo() { fluid.setDensity(oldValue); } @Override - public String describe(){ + public String describe() { return "Setting " + fluid.getName() + " density to " + newValue; } @Override - public String describeUndo(){ + public String describeUndo() { return "Restoring " + fluid.getName() + " density to " + oldValue; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } - private class ActionSetTemperature implements IUndoableAction{ + private class ActionSetTemperature implements IUndoableAction { + private final int oldValue; private final int newValue; - public ActionSetTemperature(int newValue){ + public ActionSetTemperature(int newValue) { oldValue = getTemperature(); this.newValue = newValue; } @Override - public void apply(){ + public void apply() { fluid.setTemperature(newValue); } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ + public void undo() { fluid.setTemperature(oldValue); } @Override - public String describe(){ + public String describe() { return "Setting " + fluid.getName() + " temperature to " + newValue; } @Override - public String describeUndo(){ + public String describeUndo() { return "Restoring " + fluid.getName() + " temperature to " + oldValue; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } - private class ActionSetViscosity implements IUndoableAction{ + private class ActionSetViscosity implements IUndoableAction { + private final int oldValue; private final int newValue; - public ActionSetViscosity(int newValue){ + public ActionSetViscosity(int newValue) { oldValue = getViscosity(); this.newValue = newValue; } @Override - public void apply(){ + public void apply() { fluid.setViscosity(newValue); } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ + public void undo() { fluid.setViscosity(oldValue); } @Override - public String describe(){ + public String describe() { return "Setting " + fluid.getName() + " viscosity to " + newValue; } @Override - public String describeUndo(){ + public String describeUndo() { return "Restoring " + fluid.getName() + " viscosity to " + oldValue; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } - private class ActionSetGaseous implements IUndoableAction{ + private class ActionSetGaseous implements IUndoableAction { + private final boolean oldValue; private final boolean newValue; - public ActionSetGaseous(boolean newValue){ + public ActionSetGaseous(boolean newValue) { oldValue = isGaseous(); this.newValue = newValue; } @Override - public void apply(){ + public void apply() { fluid.setGaseous(newValue); } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ + public void undo() { fluid.setGaseous(oldValue); } @Override - public String describe(){ + public String describe() { return "Setting " + fluid.getName() + " gaseous to " + newValue; } @Override - public String describeUndo(){ + public String describeUndo() { return "Restoring " + fluid.getName() + " gaseous to " + oldValue; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidStack.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidStack.java index cf2afd7..8b5edd0 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidStack.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/liquid/MCLiquidStack.java @@ -1,63 +1,56 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.liquid; import minetweaker.api.data.IData; import minetweaker.api.item.*; -import minetweaker.api.liquid.ILiquidDefinition; -import minetweaker.api.liquid.ILiquidStack; +import minetweaker.api.liquid.*; import minetweaker.api.player.IPlayer; import minetweaker.mc1102.data.NBTConverter; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.FluidStack; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * @author Stan */ -public class MCLiquidStack implements ILiquidStack{ +public class MCLiquidStack implements ILiquidStack { + private final FluidStack stack; private IData tag = null; - public MCLiquidStack(FluidStack stack){ + public MCLiquidStack(FluidStack stack) { this.stack = stack; } - private MCLiquidStack(FluidStack stack, IData tag){ + private MCLiquidStack(FluidStack stack, IData tag) { this.stack = stack; this.tag = tag; } @Override - public ILiquidDefinition getDefinition(){ + public ILiquidDefinition getDefinition() { return new MCLiquidDefinition(stack.getFluid()); } @Override - public String getName(){ + public String getName() { return stack.getFluid().getName(); } @Override - public String getDisplayName(){ + public String getDisplayName() { return stack.getFluid().getLocalizedName(stack); } @Override - public int getAmount(){ + public int getAmount() { return stack.amount; } @Override - public IData getTag(){ - if(tag == null){ - if(stack.tag == null){ + public IData getTag() { + if(tag == null) { + if(stack.tag == null) { return null; } @@ -68,46 +61,46 @@ public class MCLiquidStack implements ILiquidStack{ } @Override - public ILiquidStack withTag(IData data){ + public ILiquidStack withTag(IData data) { FluidStack result = new FluidStack(stack.getFluid(), stack.amount); result.tag = (NBTTagCompound) NBTConverter.from(data); return new MCLiquidStack(result, data.immutable()); } @Override - public ILiquidStack withAmount(int amount){ + public ILiquidStack withAmount(int amount) { FluidStack result = new FluidStack(stack.getFluid(), amount); result.tag = stack.tag; return new MCLiquidStack(result, tag); } @Override - public int getLuminosity(){ + public int getLuminosity() { return stack.getFluid().getLuminosity(stack); } @Override - public int getDensity(){ + public int getDensity() { return stack.getFluid().getDensity(stack); } @Override - public int getTemperature(){ + public int getTemperature() { return stack.getFluid().getTemperature(stack); } @Override - public int getViscosity(){ + public int getViscosity() { return stack.getFluid().getViscosity(stack); } @Override - public boolean isGaseous(){ + public boolean isGaseous() { return stack.getFluid().isGaseous(stack); } @Override - public Object getInternal(){ + public Object getInternal() { return stack; } @@ -116,47 +109,47 @@ public class MCLiquidStack implements ILiquidStack{ // ################################## @Override - public String getMark(){ + public String getMark() { return null; } @Override - public List getItems(){ + public List getItems() { return Collections.emptyList(); } @Override - public List getLiquids(){ - return Collections.singletonList(this); + public List getLiquids() { + return Collections.singletonList(this); } @Override - public IIngredient amount(int amount){ + public IIngredient amount(int amount) { return withAmount(amount); } @Override - public IIngredient or(IIngredient ingredient){ + public IIngredient or(IIngredient ingredient) { return new IngredientOr(this, ingredient); } @Override - public IIngredient transform(IItemTransformer transformer){ + public IIngredient transform(IItemTransformer transformer) { throw new UnsupportedOperationException("Liquid stack can't have transformers"); } @Override - public IIngredient only(IItemCondition condition){ + public IIngredient only(IItemCondition condition) { throw new UnsupportedOperationException("Liquid stack can't have conditions"); } @Override - public IIngredient marked(String mark){ + public IIngredient marked(String mark) { throw new UnsupportedOperationException("Liquid stack can't be marked"); } @Override - public boolean matches(IItemStack item){ + public boolean matches(IItemStack item) { return false; } @@ -166,16 +159,16 @@ public class MCLiquidStack implements ILiquidStack{ } @Override - public boolean matches(ILiquidStack liquid){ + public boolean matches(ILiquidStack liquid) { return getDefinition().equals(liquid.getDefinition()) && getAmount() <= liquid.getAmount(); } @Override - public boolean contains(IIngredient ingredient){ + public boolean contains(IIngredient ingredient) { if(!ingredient.getItems().isEmpty()) return false; - for(ILiquidStack liquid : ingredient.getLiquids()){ + for(ILiquidStack liquid : ingredient.getLiquids()) { if(!matches(liquid)) return false; } @@ -184,12 +177,12 @@ public class MCLiquidStack implements ILiquidStack{ } @Override - public IItemStack applyTransform(IItemStack item, IPlayer byPlayer){ + public IItemStack applyTransform(IItemStack item, IPlayer byPlayer) { return item; } @Override - public boolean hasTransformers(){ + public boolean hasTransformers() { return false; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/logger/MCLogger.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/logger/MCLogger.java new file mode 100644 index 0000000..f66cf84 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/logger/MCLogger.java @@ -0,0 +1,80 @@ +package minetweaker.mc1102.logger; + +import minetweaker.runtime.ILogger; +import net.minecraftforge.fml.common.*; + +import java.io.*; +import java.util.regex.Pattern; + +public class MCLogger implements ILogger { + + private static final Pattern FORMATTING_CODE_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]"); + private final Writer writer; + private final PrintWriter printWriter; + + public MCLogger(File output) { + try { + writer = new OutputStreamWriter(new FileOutputStream(output), "utf-8"); + printWriter = new PrintWriter(writer); + } catch(UnsupportedEncodingException ex) { + throw new RuntimeException("What the heck?"); + } catch(FileNotFoundException ex) { + throw new RuntimeException("Could not open log file " + output); + } + } + + @Override + public void logCommand(String message) { + try { + writer.write(stripMessage(message) + "\n"); + writer.flush(); + } catch(IOException ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void logInfo(String message) { + try { + writer.write("[" + Loader.instance().getLoaderState() + "][" + FMLCommonHandler.instance().getEffectiveSide() + "][INFO] " + stripMessage(message) + "\n"); + writer.flush(); + } catch(IOException ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void logWarning(String message) { + try { + writer.write("[" + Loader.instance().getLoaderState() + "][" + FMLCommonHandler.instance().getEffectiveSide() + "][WARNING] " + stripMessage(message) + "\n"); + writer.flush(); + } catch(IOException ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void logError(String message) { + logError(message, null); + } + + @Override + public void logError(String message, Throwable exception) { + try { + writer.write("[" + Loader.instance().getLoaderState() + "][" + FMLCommonHandler.instance().getEffectiveSide() + "][ERROR] " + stripMessage(message) + "\n"); + if(exception != null) { + exception.printStackTrace(printWriter); + } + writer.flush(); + } catch(IOException ex) { + throw new RuntimeException(ex); + } + } + + /** + * Returns a copy of the given string, with formatting codes stripped away. + */ + public String stripMessage(String message) { + return message == null ? null : FORMATTING_CODE_PATTERN.matcher(message).replaceAll(""); + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCLoadedMods.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCLoadedMods.java index d3a8409..708296d 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCLoadedMods.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCLoadedMods.java @@ -1,30 +1,28 @@ package minetweaker.mc1102.mods; -import minetweaker.api.mods.ILoadedMods; -import minetweaker.api.mods.IMod; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.ModContainer; +import minetweaker.api.mods.*; +import net.minecraftforge.fml.common.*; import stanhebben.zenscript.util.MappingIterator; -import java.util.Iterator; -import java.util.List; +import java.util.*; /** * @author Stan */ -public class MCLoadedMods implements ILoadedMods{ - public MCLoadedMods(){ +public class MCLoadedMods implements ILoadedMods { + + public MCLoadedMods() { } @Override - public boolean contains(String name){ + public boolean contains(String name) { return Loader.isModLoaded(name); } @Override - public IMod get(String name){ - for(ModContainer mod : Loader.instance().getActiveModList()){ - if(mod.getModId().equals(name)){ + public IMod get(String name) { + for(ModContainer mod : Loader.instance().getActiveModList()) { + if(mod.getModId().equals(name)) { return new MCMod(mod); } } @@ -33,11 +31,11 @@ public class MCLoadedMods implements ILoadedMods{ } @Override - public Iterator iterator(){ + public Iterator iterator() { List mods = Loader.instance().getActiveModList(); - return new MappingIterator(mods.iterator()){ + return new MappingIterator(mods.iterator()) { @Override - public IMod map(ModContainer value){ + public IMod map(ModContainer value) { return new MCMod(value); } }; diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCMod.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCMod.java index c423669..9f4592f 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCMod.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/mods/MCMod.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.mods; import minetweaker.api.mods.IMod; @@ -12,30 +6,31 @@ import net.minecraftforge.fml.common.ModContainer; /** * @author Stan */ -public class MCMod implements IMod{ +public class MCMod implements IMod { + private final ModContainer mod; - public MCMod(ModContainer mod){ + public MCMod(ModContainer mod) { this.mod = mod; } @Override - public String getId(){ + public String getId() { return mod.getModId(); } @Override - public String getName(){ + public String getName() { return mod.getName(); } @Override - public String getVersion(){ + public String getVersion() { return mod.getVersion(); } @Override - public String getDescription(){ + public String getDescription() { return mod.getMetadata().description; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardHandler.java index be5c668..5c91e94 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardHandler.java @@ -1,31 +1,27 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.network; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.common.network.simpleimpl.*; import java.awt.*; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.*; /** * @author Stan */ -public class MineTweakerCopyClipboardHandler implements IMessageHandler{ +public class MineTweakerCopyClipboardHandler implements IMessageHandler { + @Override - public IMessage onMessage(MineTweakerCopyClipboardPacket message, MessageContext ctx){ - if(Desktop.isDesktopSupported()){ + public IMessage onMessage(MineTweakerCopyClipboardPacket message, MessageContext ctx) { + Minecraft.getMinecraft().addScheduledTask(() -> handle(message, ctx)); + return null; + } + + private void handle(MineTweakerCopyClipboardPacket message, MessageContext ctx) { + if(Desktop.isDesktopSupported()) { StringSelection stringSelection = new StringSelection(message.getData()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); } - - return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardPacket.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardPacket.java index 94d774e..410bc50 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardPacket.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerCopyClipboardPacket.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.network; import io.netty.buffer.ByteBuf; @@ -16,27 +10,28 @@ import static com.google.common.base.Charsets.UTF_8; /** * @author Stan */ -public class MineTweakerCopyClipboardPacket implements IMessage{ +public class MineTweakerCopyClipboardPacket implements IMessage { + private String data; - public MineTweakerCopyClipboardPacket(){ + public MineTweakerCopyClipboardPacket() { } - public MineTweakerCopyClipboardPacket(String data){ + public MineTweakerCopyClipboardPacket(String data) { this.data = data; } - public String getData(){ + public String getData() { return data; } @Override - public void fromBytes(ByteBuf buf){ + public void fromBytes(ByteBuf buf) { data = UTF_8.decode(ByteBuffer.wrap(buf.array())).toString().trim(); } @Override - public void toBytes(ByteBuf buf){ + public void toBytes(ByteBuf buf) { buf.writeBytes(UTF_8.encode(data).array()); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsHandler.java index 63e54ad..34cba0c 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsHandler.java @@ -1,32 +1,28 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.network; -import minetweaker.MineTweakerAPI; -import minetweaker.MineTweakerImplementationAPI; +import minetweaker.*; import minetweaker.mc1102.client.MCClient; import minetweaker.runtime.providers.ScriptProviderMemory; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.common.network.simpleimpl.*; /** * @author Stan */ -public class MineTweakerLoadScriptsHandler implements IMessageHandler{ +public class MineTweakerLoadScriptsHandler implements IMessageHandler { + @Override - public IMessage onMessage(MineTweakerLoadScriptsPacket message, MessageContext ctx){ - if(MineTweakerAPI.server == null){ + public IMessage onMessage(MineTweakerLoadScriptsPacket message, MessageContext ctx) { + Minecraft.getMinecraft().addScheduledTask(() -> handle(message, ctx)); + return null; + } + + private void handle(MineTweakerLoadScriptsPacket message, MessageContext ctx) { + if(MineTweakerAPI.server == null) { MineTweakerAPI.client = new MCClient(); - + MineTweakerImplementationAPI.setScriptProvider(new ScriptProviderMemory(message.getData())); MineTweakerImplementationAPI.reload(); } - - return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsPacket.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsPacket.java index 9057751..0971b8a 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsPacket.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerLoadScriptsPacket.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.network; import io.netty.buffer.ByteBuf; @@ -12,30 +6,31 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage; /** * @author Stan */ -public class MineTweakerLoadScriptsPacket implements IMessage{ +public class MineTweakerLoadScriptsPacket implements IMessage { + private byte[] data; - - public MineTweakerLoadScriptsPacket(){ + + public MineTweakerLoadScriptsPacket() { // used for deserialization } - - public MineTweakerLoadScriptsPacket(byte[] data){ + + public MineTweakerLoadScriptsPacket(byte[] data) { this.data = data; } - - public byte[] getData(){ + + public byte[] getData() { return data; } - + @Override - public void fromBytes(ByteBuf buf){ + public void fromBytes(ByteBuf buf) { int size = buf.readInt(); data = new byte[size]; buf.readBytes(data); } - + @Override - public void toBytes(ByteBuf buf){ + public void toBytes(ByteBuf buf) { buf.writeInt(data.length); buf.writeBytes(data); } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserHandler.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserHandler.java index d2033a7..def6434 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserHandler.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserHandler.java @@ -1,37 +1,32 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.network; -import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.common.network.simpleimpl.*; import java.awt.*; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; +import java.net.*; /** * @author Stan */ -public class MineTweakerOpenBrowserHandler implements IMessageHandler{ - @Override - public IMessage onMessage(MineTweakerOpenBrowserPacket message, MessageContext ctx){ - if(Desktop.isDesktopSupported()){ - Desktop desktop = Desktop.getDesktop(); - try{ - desktop.browse(new URI(message.getUrl())); - }catch(IOException e){ - }catch(URISyntaxException e){ - } - }else{ - System.out.println("Desktop not supported"); - } +public class MineTweakerOpenBrowserHandler implements IMessageHandler { + @Override + public IMessage onMessage(MineTweakerOpenBrowserPacket message, MessageContext ctx) { + Minecraft.getMinecraft().addScheduledTask(() -> handle(message, ctx)); return null; } + + private void handle(MineTweakerOpenBrowserPacket message, MessageContext ctx) { + if(Desktop.isDesktopSupported()) { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.browse(new URI(message.getUrl())); + } catch(IOException | URISyntaxException ignored) { + } + } else { + System.out.println("Desktop not supported"); + } + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserPacket.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserPacket.java index 68f6f63..3cd3899 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserPacket.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/network/MineTweakerOpenBrowserPacket.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.network; import io.netty.buffer.ByteBuf; @@ -15,30 +9,31 @@ import java.nio.charset.Charset; /** * @author Stan */ -public class MineTweakerOpenBrowserPacket implements IMessage{ +public class MineTweakerOpenBrowserPacket implements IMessage { + private static final Charset UTF8 = Charset.forName("utf-8"); private String url; - public MineTweakerOpenBrowserPacket(){ + public MineTweakerOpenBrowserPacket() { } - public MineTweakerOpenBrowserPacket(String url){ + public MineTweakerOpenBrowserPacket(String url) { this.url = url; } - public String getUrl(){ + public String getUrl() { return url; } @Override - public void fromBytes(ByteBuf buf){ + public void fromBytes(ByteBuf buf) { url = UTF8.decode(ByteBuffer.wrap(buf.array())).toString().trim(); } @Override - public void toBytes(ByteBuf buf){ + public void toBytes(ByteBuf buf) { buf.writeBytes(UTF8.encode(url).array()); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDict.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDict.java index 61143b8..563babd 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDict.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDict.java @@ -1,35 +1,28 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.oredict; import minetweaker.api.minecraft.MineTweakerMC; -import minetweaker.api.oredict.IOreDict; -import minetweaker.api.oredict.IOreDictEntry; +import minetweaker.api.oredict.*; import net.minecraftforge.oredict.OreDictionary; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import static minetweaker.api.minecraft.MineTweakerMC.getOreDict; /** * @author Stan */ -public class MCOreDict implements IOreDict{ +public class MCOreDict implements IOreDict { + @Override - public IOreDictEntry get(String name){ + public IOreDictEntry get(String name) { return getOreDict(name); } @Override - public List getEntries(){ - List entries = new ArrayList(); - for(String key : OreDictionary.getOreNames()){ - if(!OreDictionary.getOres(key).isEmpty()){ + public List getEntries() { + List entries = new ArrayList<>(); + for(String key : OreDictionary.getOreNames()) { + if(!OreDictionary.getOres(key).isEmpty()) { entries.add(MineTweakerMC.getOreDict(key)); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDictEntry.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDictEntry.java index 184bd84..33a5ba1 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDictEntry.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/oredict/MCOreDictEntry.java @@ -1,29 +1,20 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.oredict; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import minetweaker.api.item.*; import minetweaker.api.liquid.ILiquidStack; -import minetweaker.api.oredict.IOreDictEntry; -import minetweaker.api.oredict.IngredientOreDict; +import minetweaker.api.minecraft.MineTweakerMC; +import minetweaker.api.oredict.*; import minetweaker.api.player.IPlayer; import minetweaker.mc1102.util.MineTweakerHacks; import minetweaker.util.ArrayUtil; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStackWildcardSize; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; +import static minetweaker.api.minecraft.MineTweakerMC.*; /** * @author Stan @@ -63,16 +54,16 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public void add(IItemStack item) { ItemStack stack = getItemStack(item); - if (stack != null) { + if(stack != null) { MineTweakerAPI.apply(new ActionAddItem(id, stack)); } } @Override public void addItems(IItemStack[] items) { - for (IItemStack item : items) { + for(IItemStack item : items) { ItemStack stack = getItemStack(item); - if (stack != null) { + if(stack != null) { MineTweakerAPI.apply(new ActionAddItem(id, stack)); } } @@ -80,7 +71,7 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public void addAll(IOreDictEntry entry) { - if (entry instanceof MCOreDictEntry) { + if(entry instanceof MCOreDictEntry) { MineTweakerAPI.apply(new ActionAddAll(id, ((MCOreDictEntry) entry).id)); } else { MineTweakerAPI.logError("not a valid entry"); @@ -90,30 +81,30 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public void remove(IItemStack item) { ItemStack result = null; - for (ItemStack itemStack : OreDictionary.getOres(getName())) { - if (item.matches(getIItemStackWildcardSize(itemStack))) { + for(ItemStack itemStack : OreDictionary.getOres(getName())) { + if(item.matches(getIItemStackWildcardSize(itemStack))) { result = itemStack; break; } } - if (result != null) { + if(result != null) { MineTweakerAPI.apply(new ActionRemoveItem(id, result)); } } @Override public void removeItems(IItemStack[] items) { - for (IItemStack item : items) { + for(IItemStack item : items) { ItemStack result = null; - for (ItemStack itemStack : OreDictionary.getOres(id)) { - if (item.matches(getIItemStackWildcardSize(itemStack))) { + for(ItemStack itemStack : OreDictionary.getOres(id)) { + if(item.matches(getIItemStackWildcardSize(itemStack))) { result = itemStack; break; } } - if (result != null) { + if(result != null) { MineTweakerAPI.apply(new ActionRemoveItem(id, result)); } } @@ -121,8 +112,8 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public boolean contains(IItemStack item) { - for (ItemStack itemStack : OreDictionary.getOres(getName())) { - if (getIItemStackWildcardSize(itemStack).matches(item)) { + for(ItemStack itemStack : OreDictionary.getOres(getName())) { + if(getIItemStackWildcardSize(itemStack).matches(item)) { return true; } } @@ -132,7 +123,7 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public void mirror(IOreDictEntry other) { - if (other instanceof MCOreDictEntry) { + if(other instanceof MCOreDictEntry) { MineTweakerAPI.apply(new ActionMirror(id, ((MCOreDictEntry) other).id)); } else { MineTweakerAPI.logError("not a valid oredict entry"); @@ -151,11 +142,7 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public List getItems() { - List result = new ArrayList(); - for (ItemStack item : OreDictionary.getOres(getName())) { - result.add(getIItemStackWildcardSize(item)); - } - return result; + return OreDictionary.getOres(getName()).stream().map(MineTweakerMC::getIItemStackWildcardSize).collect(Collectors.toList()); } @Override @@ -206,8 +193,8 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public boolean contains(IIngredient ingredient) { List items = ingredient.getItems(); - for (IItemStack item : items) { - if (!matches(item)) + for(IItemStack item : items) { + if(!matches(item)) return false; } @@ -245,9 +232,7 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public boolean equals(Object other) { - if (!(other instanceof MCOreDictEntry)) - return false; - return ((MCOreDictEntry) other).id == id; + return other instanceof MCOreDictEntry && Objects.equals(((MCOreDictEntry) other).id, id); } // ###################### @@ -255,6 +240,7 @@ public class MCOreDictEntry implements IOreDictEntry { // ###################### private static class ActionAddItem implements IUndoableAction { + private final String id; private final ItemStack item; @@ -297,6 +283,7 @@ public class MCOreDictEntry implements IOreDictEntry { } private static class ActionMirror implements IUndoableAction { + private final String idTarget; private final String idSource; @@ -349,6 +336,7 @@ public class MCOreDictEntry implements IOreDictEntry { } private static class ActionRemoveItem implements IUndoableAction { + private final String id; private final ItemStack item; @@ -391,6 +379,7 @@ public class MCOreDictEntry implements IOreDictEntry { } private static class ActionAddAll implements IUndoableAction { + private final String idTarget; private final String idSource; @@ -401,7 +390,7 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public void apply() { - for (ItemStack stack : OreDictionary.getOres(idSource)) { + for(ItemStack stack : OreDictionary.getOres(idSource)) { OreDictionary.registerOre(idTarget, stack); } } @@ -414,7 +403,7 @@ public class MCOreDictEntry implements IOreDictEntry { @Override public void undo() { int targetOreId = OreDictionary.getOreID(idTarget); - for (ItemStack stack : OreDictionary.getOres(idSource)) { + for(ItemStack stack : OreDictionary.getOres(idSource)) { OREDICT_CONTENTS.get(targetOreId).remove(stack); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/CommandBlockPlayer.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/CommandBlockPlayer.java index f9ad6c4..91e9c58 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/CommandBlockPlayer.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/CommandBlockPlayer.java @@ -6,117 +6,130 @@ import minetweaker.api.data.IData; import minetweaker.api.item.IItemStack; import minetweaker.api.player.IPlayer; import net.minecraft.command.ICommandSender; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.*; /** * @author Jared */ -public class CommandBlockPlayer implements IPlayer{ +public class CommandBlockPlayer implements IPlayer { + private final ICommandSender sender; - public CommandBlockPlayer(ICommandSender sender){ + public CommandBlockPlayer(ICommandSender sender) { this.sender = sender; } - public ICommandSender getInternal(){ + public ICommandSender getInternal() { return sender; } @Override - public String getId(){ + public String getId() { return null; // TODO: we should be having this for MC 1.7.10, right? } @Override - public String getName(){ + public String getName() { return sender.getName(); } @Override - public IData getData(){ + public IData getData() { return null; } - + @Override - public void update(IData data){ + public int getXP() { + return 0; + } + + @Override + public void setXP(int xp) { + + } + + @Override + public void removeXP(int xp) { + + } + + @Override + public void update(IData data) { } @Override - public void sendChat(IChatMessage message){ + public void sendChat(IChatMessage message) { Object internal = message.getInternal(); - if(!(internal instanceof ITextComponent)){ + if(!(internal instanceof ITextComponent)) { MineTweakerAPI.logError("not a valid chat message"); return; } - sender.addChatMessage((ITextComponent) internal); + sender.sendMessage((ITextComponent) internal); } @Override - public void sendChat(String message){ - sender.addChatMessage(new TextComponentString(message)); + public void sendChat(String message) { + sender.sendMessage(new TextComponentString(message)); } @Override - public int getHotbarSize(){ + public int getHotbarSize() { return 0; } @Override - public IItemStack getHotbarStack(int i){ + public IItemStack getHotbarStack(int i) { return null; } @Override - public int getInventorySize(){ + public int getInventorySize() { return 0; } @Override - public IItemStack getInventoryStack(int i){ + public IItemStack getInventoryStack(int i) { return null; } @Override - public IItemStack getCurrentItem(){ + public IItemStack getCurrentItem() { return null; } @Override - public boolean isCreative(){ + public boolean isCreative() { return false; } @Override - public boolean isAdventure(){ + public boolean isAdventure() { return false; } @Override - public void openBrowser(String url){ + public void openBrowser(String url) { } @Override - public void copyToClipboard(String value){ + public void copyToClipboard(String value) { } @Override - public boolean equals(Object other){ - if(other.getClass() != this.getClass()) - return false; + public boolean equals(Object other) { + return other.getClass() == this.getClass() && ((CommandBlockPlayer) other).sender.equals(sender); - return ((CommandBlockPlayer) other).sender.equals(sender); } @Override - public int hashCode(){ + public int hashCode() { int hash = 5; hash = 23 * hash + (this.sender != null ? this.sender.hashCode() : 0); return hash; } @Override - public void give(IItemStack stack){ + public void give(IItemStack stack) { } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/MCPlayer.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/MCPlayer.java index e37e2b3..0c5f342 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/MCPlayer.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/MCPlayer.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.player; import minetweaker.MineTweakerAPI; @@ -14,128 +8,140 @@ import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.player.IPlayer; import minetweaker.mc1102.MineTweakerMod; import minetweaker.mc1102.data.NBTConverter; -import minetweaker.mc1102.network.MineTweakerCopyClipboardPacket; -import minetweaker.mc1102.network.MineTweakerOpenBrowserPacket; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import minetweaker.mc1102.network.*; +import net.minecraft.entity.player.*; +import net.minecraft.util.text.*; /** * @author Stan */ -public class MCPlayer implements IPlayer{ +public class MCPlayer implements IPlayer { + private final EntityPlayer player; - public MCPlayer(EntityPlayer player){ + public MCPlayer(EntityPlayer player) { this.player = player; } - public EntityPlayer getInternal(){ + public EntityPlayer getInternal() { return player; } @Override - public String getId(){ + public String getId() { return null; // TODO: we should be having this for MC 1.7.10, right? } @Override - public String getName(){ + public String getName() { return player.getName(); } @Override - public IData getData(){ + public IData getData() { return NBTConverter.from(player.getEntityData(), true); } @Override - public void update(IData data){ + public int getXP() { + return player.experienceLevel; + } + + @Override + public void setXP(int xp) { + player.removeExperienceLevel(player.experienceLevel); + player.addExperienceLevel(xp); + } + + @Override + public void removeXP(int xp) { + player.removeExperienceLevel(xp); + } + + @Override + public void update(IData data) { NBTConverter.updateMap(player.getEntityData(), data); } @Override - public void sendChat(IChatMessage message){ + public void sendChat(IChatMessage message) { Object internal = message.getInternal(); - if(!(internal instanceof ITextComponent)){ + if(!(internal instanceof ITextComponent)) { MineTweakerAPI.logError("not a valid chat message"); return; } - player.addChatMessage((ITextComponent) internal); + player.sendMessage((ITextComponent) internal); } @Override - public void sendChat(String message){ - player.addChatMessage(new TextComponentString(message)); + public void sendChat(String message) { + player.sendMessage(new TextComponentString(message)); } @Override - public int getHotbarSize(){ + public int getHotbarSize() { return 9; } @Override - public IItemStack getHotbarStack(int i){ + public IItemStack getHotbarStack(int i) { return i < 0 || i >= 9 ? null : MineTweakerMC.getIItemStack(player.inventory.getStackInSlot(i)); } @Override - public int getInventorySize(){ + public int getInventorySize() { return player.inventory.getSizeInventory(); } @Override - public IItemStack getInventoryStack(int i){ + public IItemStack getInventoryStack(int i) { return MineTweakerMC.getIItemStack(player.inventory.getStackInSlot(i)); } @Override - public IItemStack getCurrentItem(){ + public IItemStack getCurrentItem() { return MineTweakerMC.getIItemStack(player.inventory.getCurrentItem()); } @Override - public boolean isCreative(){ + public boolean isCreative() { return player.capabilities.isCreativeMode; } @Override - public boolean isAdventure(){ + public boolean isAdventure() { return !player.capabilities.allowEdit; } @Override - public void openBrowser(String url){ - if(player instanceof EntityPlayerMP){ + public void openBrowser(String url) { + if(player instanceof EntityPlayerMP) { MineTweakerMod.NETWORK.sendTo(new MineTweakerOpenBrowserPacket(url), (EntityPlayerMP) player); } } @Override - public void copyToClipboard(String value){ - if(player instanceof EntityPlayerMP){ + public void copyToClipboard(String value) { + if(player instanceof EntityPlayerMP) { MineTweakerMod.NETWORK.sendTo(new MineTweakerCopyClipboardPacket(value), (EntityPlayerMP) player); } } @Override - public boolean equals(Object other){ - if(other.getClass() != this.getClass()) - return false; + public boolean equals(Object other) { + return other.getClass() == this.getClass() && ((MCPlayer) other).player == player; - return ((MCPlayer) other).player == player; } @Override - public int hashCode(){ + public int hashCode() { int hash = 5; hash = 23 * hash + (this.player != null ? this.player.hashCode() : 0); return hash; } @Override - public void give(IItemStack stack){ + public void give(IItemStack stack) { player.inventory.addItemStackToInventory(MineTweakerMC.getItemStack(stack).copy()); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/RconPlayer.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/RconPlayer.java index 7939156..5980d9b 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/RconPlayer.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/player/RconPlayer.java @@ -6,117 +6,130 @@ import minetweaker.api.data.IData; import minetweaker.api.item.IItemStack; import minetweaker.api.player.IPlayer; import net.minecraft.command.ICommandSender; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.*; /** * @author Jared */ -public class RconPlayer implements IPlayer{ +public class RconPlayer implements IPlayer { + private final ICommandSender sender; - public RconPlayer(ICommandSender sender){ + public RconPlayer(ICommandSender sender) { this.sender = sender; } - public ICommandSender getInternal(){ + public ICommandSender getInternal() { return sender; } @Override - public String getId(){ + public String getId() { return null; // TODO: we should be having this for MC 1.7.10, right? } @Override - public String getName(){ + public String getName() { return sender.getName(); } @Override - public IData getData(){ + public IData getData() { return null; } - + @Override - public void update(IData data){ + public int getXP() { + return 0; + } + + @Override + public void setXP(int xp) { + + } + + @Override + public void removeXP(int xp) { + + } + + @Override + public void update(IData data) { } @Override - public void sendChat(IChatMessage message){ + public void sendChat(IChatMessage message) { Object internal = message.getInternal(); - if(!(internal instanceof ITextComponent)){ + if(!(internal instanceof ITextComponent)) { MineTweakerAPI.logError("not a valid chat message"); return; } - sender.addChatMessage((ITextComponent) internal); + sender.sendMessage((ITextComponent) internal); } @Override - public void sendChat(String message){ - sender.addChatMessage(new TextComponentString(message)); + public void sendChat(String message) { + sender.sendMessage(new TextComponentString(message)); } @Override - public int getHotbarSize(){ + public int getHotbarSize() { return 0; } @Override - public IItemStack getHotbarStack(int i){ + public IItemStack getHotbarStack(int i) { return null; } @Override - public int getInventorySize(){ + public int getInventorySize() { return 0; } @Override - public IItemStack getInventoryStack(int i){ + public IItemStack getInventoryStack(int i) { return null; } @Override - public IItemStack getCurrentItem(){ + public IItemStack getCurrentItem() { return null; } @Override - public boolean isCreative(){ + public boolean isCreative() { return false; } @Override - public boolean isAdventure(){ + public boolean isAdventure() { return false; } @Override - public void openBrowser(String url){ + public void openBrowser(String url) { } @Override - public void copyToClipboard(String value){ + public void copyToClipboard(String value) { } @Override - public boolean equals(Object other){ - if(other.getClass() != this.getClass()) - return false; + public boolean equals(Object other) { + return other.getClass() == this.getClass() && ((RconPlayer) other).sender == sender; - return ((RconPlayer) other).sender == sender; } @Override - public int hashCode(){ + public int hashCode() { int hash = 5; hash = 23 * hash + (this.sender != null ? this.sender.hashCode() : 0); return hash; } @Override - public void give(IItemStack stack){ + public void give(IItemStack stack) { } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCCraftingInventory.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCCraftingInventory.java index 8cdc869..7f39c13 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCCraftingInventory.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCCraftingInventory.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; import minetweaker.api.item.IItemStack; @@ -15,16 +9,15 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; -import java.util.List; +import java.util.*; import static minetweaker.api.minecraft.MineTweakerMC.*; /** * @author Stan */ -public class MCCraftingInventory implements ICraftingInventory{ - private static final ThreadLocal cache = new ThreadLocal(); - private static final ThreadLocal cache2 = new ThreadLocal(); +public class MCCraftingInventory implements ICraftingInventory { + private final IInventory inventory; private final IPlayer player; private final EntityPlayer playerOrig; @@ -33,7 +26,8 @@ public class MCCraftingInventory implements ICraftingInventory{ private IItemStack[] stacks; private ItemStack[] original; private int stackCount; - private MCCraftingInventory(InventoryCrafting inventory){ + + private MCCraftingInventory(InventoryCrafting inventory) { this.inventory = inventory; width = height = (int) Math.sqrt(inventory.getSizeInventory()); stacks = new IItemStack[width * height]; @@ -42,22 +36,23 @@ public class MCCraftingInventory implements ICraftingInventory{ update(); Container container = MineTweakerHacks.getCraftingContainer(inventory); - if(container != null){ + if(container != null) { List slots = container.inventorySlots; - if(!slots.isEmpty() && slots.get(0) instanceof SlotCrafting){ + if(!slots.isEmpty() && slots.get(0) instanceof SlotCrafting) { SlotCrafting slotCrafting = (SlotCrafting) slots.get(0); playerOrig = MineTweakerHacks.getCraftingSlotPlayer(slotCrafting); player = getIPlayer(playerOrig); - }else{ + } else { playerOrig = null; player = null; } - }else{ + } else { playerOrig = null; player = null; } } - public MCCraftingInventory(IInventory inventory, EntityPlayer player){ + + public MCCraftingInventory(IInventory inventory, EntityPlayer player) { this.inventory = inventory; width = height = (int) Math.sqrt(inventory.getSizeInventory()); stacks = new IItemStack[width * height]; @@ -69,47 +64,33 @@ public class MCCraftingInventory implements ICraftingInventory{ this.player = player == null ? null : new MCPlayer(player); } - public static MCCraftingInventory get(InventoryCrafting inventory){ - if(cache.get() == null || cache.get().inventory != inventory){ + public static MCCraftingInventory get(InventoryCrafting inventory) { MCCraftingInventory result = new MCCraftingInventory(inventory); - cache.set(result); return result; - }else{ - MCCraftingInventory result = cache.get(); - result.update(); - return result; - } } - public static MCCraftingInventory get(IInventory inventory, EntityPlayer player){ - if(cache2.get() == null || cache2.get().inventory != inventory || cache2.get().player != player){ + public static MCCraftingInventory get(IInventory inventory, EntityPlayer player) { MCCraftingInventory result = new MCCraftingInventory(inventory, player); - cache2.set(result); return result; - }else{ - MCCraftingInventory result = cache2.get(); - result.update(); - return result; - } } - private void update(){ - if(inventory.getSizeInventory() != original.length){ + private void update() { + if(inventory.getSizeInventory() != original.length) { width = height = (int) Math.sqrt(inventory.getSizeInventory()); stacks = new IItemStack[inventory.getSizeInventory()]; original = new ItemStack[stacks.length]; stackCount = 0; } - for(int i = 0; i < inventory.getSizeInventory(); i++){ - if(changed(i)){ + for(int i = 0; i < inventory.getSizeInventory(); i++) { + if(changed(i)) { // System.out.println("Slot " + i + " changed"); original[i] = inventory.getStackInSlot(i); - if(inventory.getStackInSlot(i) != null){ + if(inventory.getStackInSlot(i) != null) { if(stacks[i] == null) stackCount++; stacks[i] = getIItemStack(original[i]); - }else{ + } else { if(stacks[i] != null) stackCount--; stacks[i] = null; @@ -120,53 +101,53 @@ public class MCCraftingInventory implements ICraftingInventory{ } @Override - public IPlayer getPlayer(){ + public IPlayer getPlayer() { return player; } @Override - public int getSize(){ + public int getSize() { return width * height; } @Override - public int getWidth(){ + public int getWidth() { return width; } @Override - public int getHeight(){ + public int getHeight() { return height; } @Override - public int getStackCount(){ + public int getStackCount() { return stackCount; } @Override - public IItemStack getStack(int i){ + public IItemStack getStack(int i) { return stacks[i]; } @Override - public IItemStack getStack(int x, int y){ + public IItemStack getStack(int x, int y) { return stacks[y * width + x]; } @Override - public void setStack(int x, int y, IItemStack stack){ + public void setStack(int x, int y, IItemStack stack) { // System.out.println("SetStack(" + x + ", " + y + ") " + stack); int ix = y * width + x; - if(stack != stacks[ix]){ - if(stack == null){ + if(stack != stacks[ix]) { + if(stack == null) { stackCount--; inventory.setInventorySlotContents(ix, null); - }else{ + } else { inventory.setInventorySlotContents(ix, getItemStack(stack)); - if(stacks[ix] == null){ + if(stacks[ix] == null) { stackCount++; } } @@ -175,17 +156,17 @@ public class MCCraftingInventory implements ICraftingInventory{ } @Override - public void setStack(int i, IItemStack stack){ + public void setStack(int i, IItemStack stack) { // System.out.println("SetStack(" + i + ") " + stack); - if(stack != stacks[i]){ - if(stack == null){ + if(stack != stacks[i]) { + if(stack == null) { stackCount--; inventory.setInventorySlotContents(i, null); - }else{ + } else { inventory.setInventorySlotContents(i, getItemStack(stack)); - if(stacks[i] == null){ + if(stacks[i] == null) { stackCount++; } } @@ -193,10 +174,22 @@ public class MCCraftingInventory implements ICraftingInventory{ } } - private boolean changed(int i){ - if(original[i] != inventory.getStackInSlot(i)) - return true; - return original[i] != null && stacks[i].getAmount() != original[i].stackSize; - + private boolean changed(int i) { + return original[i] != inventory.getStackInSlot(i) || original[i] != null && stacks[i].getAmount() != original[i].stackSize; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("MCCraftingInventory{"); + sb.append("inventory=").append(inventory); + sb.append(", player=").append(player); + sb.append(", playerOrig=").append(playerOrig); + sb.append(", width=").append(width); + sb.append(", height=").append(height); + sb.append(", stacks=").append(Arrays.toString(stacks)); + sb.append(", original=").append(Arrays.toString(original)); + sb.append(", stackCount=").append(stackCount); + sb.append('}'); + return sb.toString(); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCRecipeManager.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCRecipeManager.java index ef1b79d..6586084 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCRecipeManager.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/MCRecipeManager.java @@ -1,27 +1,19 @@ package minetweaker.mc1102.recipes; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; +import minetweaker.*; +import minetweaker.api.item.*; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.player.IPlayer; import minetweaker.api.recipes.*; import minetweaker.mc1102.util.MineTweakerHacks; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.ShapedRecipes; -import net.minecraft.item.crafting.ShapelessRecipes; -import net.minecraftforge.oredict.ShapedOreRecipe; -import net.minecraftforge.oredict.ShapelessOreRecipe; +import net.minecraft.item.crafting.*; +import net.minecraftforge.oredict.*; import stanhebben.zenscript.annotations.Optional; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import static minetweaker.api.minecraft.MineTweakerMC.*; @@ -29,12 +21,13 @@ import static minetweaker.api.minecraft.MineTweakerMC.*; * @author Stan */ public class MCRecipeManager implements IRecipeManager { + private final List recipes; private final List transformerRecipes; public MCRecipeManager() { recipes = CraftingManager.getInstance().getRecipeList(); - transformerRecipes = new ArrayList(); + transformerRecipes = new ArrayList<>(); } private static boolean matches(Object input, IIngredient ingredient) { @@ -70,21 +63,19 @@ public class MCRecipeManager implements IRecipeManager { @Override public List getRecipesFor(IIngredient ingredient) { - List results = new ArrayList(); + List results = new ArrayList<>(); - for(IRecipe recipe : recipes) { - if(ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))) { - ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe); - results.add(converted); - } - } + recipes.stream().filter(recipe -> ingredient.matches(MineTweakerMC.getIItemStack(recipe.getRecipeOutput()))).forEach(recipe -> { + ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe); + results.add(converted); + }); return results; } @Override public List getAll() { - List results = new ArrayList(); + List results = new ArrayList<>(); for(IRecipe recipe : recipes) { ICraftingRecipe converted = RecipeConverter.toCraftingRecipe(recipe); @@ -96,8 +87,8 @@ public class MCRecipeManager implements IRecipeManager { @Override public int remove(IIngredient output, @Optional boolean nbtMatch) { - List toRemove = new ArrayList(); - List removeIndex = new ArrayList(); + List toRemove = new ArrayList<>(); + List removeIndex = new ArrayList<>(); for(int i = 0; i < recipes.size(); i++) { IRecipe recipe = recipes.get(i); @@ -116,58 +107,58 @@ public class MCRecipeManager implements IRecipeManager { } @Override - public void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function) { - addShaped(output, ingredients, function, false); + public void addShaped(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action) { + addShaped(output, ingredients, function, action, false); } @Override - public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function) { - addShaped(output, ingredients, function, true); + public void addShapedMirrored(IItemStack output, IIngredient[][] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action) { + addShaped(output, ingredients, function, action, true); } @Override - public void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function) { - ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function); + public void addShapeless(IItemStack output, IIngredient[] ingredients, @Optional IRecipeFunction function, @Optional IRecipeAction action) { + ShapelessRecipe recipe = new ShapelessRecipe(output, ingredients, function, action); IRecipe irecipe = RecipeConverter.convert(recipe); MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe)); } - + @Override - public int removeShaped(IIngredient output, @Optional IIngredient[][] ingredients) { + public int removeShaped(IIngredient output, IIngredient[][] ingredients) { int ingredientsWidth = 0; int ingredientsHeight = 0; - + if(ingredients != null) { ingredientsHeight = ingredients.length; - + for(int i = 0; i < ingredients.length; i++) { ingredientsWidth = Math.max(ingredientsWidth, ingredients[i].length); } } - + List toRemove = new ArrayList(); List removeIndex = new ArrayList(); outer: for(int i = 0; i < recipes.size(); i++) { IRecipe recipe = recipes.get(i); - + if(recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) { continue; } - + if(ingredients != null) { if(recipe instanceof ShapedRecipes) { ShapedRecipes srecipe = (ShapedRecipes) recipe; if(ingredientsWidth != srecipe.recipeWidth || ingredientsHeight != srecipe.recipeHeight) { continue; } - + for(int j = 0; j < ingredientsHeight; j++) { IIngredient[] row = ingredients[j]; for(int k = 0; k < ingredientsWidth; k++) { IIngredient ingredient = k > row.length ? null : row[k]; ItemStack recipeIngredient = srecipe.recipeItems[j * srecipe.recipeWidth + k]; - + if(!matches(recipeIngredient, ingredient)) { continue outer; } @@ -180,7 +171,7 @@ public class MCRecipeManager implements IRecipeManager { if(ingredientsWidth != recipeWidth || ingredientsHeight != recipeHeight) { continue; } - + for(int j = 0; j < ingredientsHeight; j++) { IIngredient[] row = ingredients[j]; for(int k = 0; k < ingredientsWidth; k++) { @@ -191,47 +182,53 @@ public class MCRecipeManager implements IRecipeManager { } } } + } else { + if(recipe instanceof ShapelessRecipes) { + continue; + } else if(recipe instanceof ShapelessOreRecipe) { + continue; + } else { + } } } else { - if(recipe instanceof ShapedRecipes) { - - } else if(recipe instanceof ShapedOreRecipe) { - - } else { + if(recipe instanceof ShapelessRecipes) { continue; + } else if(recipe instanceof ShapelessOreRecipe) { + continue; + } else { } } - + toRemove.add(recipe); removeIndex.add(i); } - + MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex)); return toRemove.size(); } - + @Override - public int removeShapeless(IIngredient output, @Optional IIngredient[] ingredients, @Optional boolean wildcard) { + public int removeShapeless(IIngredient output, IIngredient[] ingredients, boolean wildcard) { List toRemove = new ArrayList(); List removeIndex = new ArrayList(); outer: for(int i = 0; i < recipes.size(); i++) { IRecipe recipe = recipes.get(i); - + if(recipe.getRecipeOutput() == null || !output.matches(getIItemStack(recipe.getRecipeOutput()))) { continue; } - + if(ingredients != null) { if(recipe instanceof ShapelessRecipes) { ShapelessRecipes srecipe = (ShapelessRecipes) recipe; - + if(ingredients.length > srecipe.getRecipeSize()) { continue; } else if(!wildcard && ingredients.length < srecipe.getRecipeSize()) { continue; } - + checkIngredient: for(int j = 0; j < ingredients.length; j++) { for(int k = 0; k < srecipe.getRecipeSize(); k++) { @@ -239,20 +236,20 @@ public class MCRecipeManager implements IRecipeManager { continue checkIngredient; } } - + continue outer; } } else if(recipe instanceof ShapelessOreRecipe) { ShapelessOreRecipe srecipe = (ShapelessOreRecipe) recipe; ArrayList inputs = srecipe.getInput(); - + if(inputs.size() < ingredients.length) { continue; } if(!wildcard && inputs.size() > ingredients.length) { continue; } - + checkIngredient: for(int j = 0; j < ingredients.length; j++) { for(int k = 0; k < srecipe.getRecipeSize(); k++) { @@ -260,24 +257,31 @@ public class MCRecipeManager implements IRecipeManager { continue checkIngredient; } } - + continue outer; } } - } else { - if(recipe instanceof ShapelessRecipes) { - - } else if(recipe instanceof ShapelessOreRecipe) { - - } else { + if(recipe instanceof ShapedRecipes) { continue; + } else if(recipe instanceof ShapedOreRecipe) { + continue; + } else { + } + } else { + if(recipe instanceof ShapedRecipes) { + continue; + } else if(recipe instanceof ShapedOreRecipe) { + continue; + } else { + } } + toRemove.add(recipe); removeIndex.add(i); } - + MineTweakerAPI.apply(new ActionRemoveRecipes(toRemove, removeIndex)); return toRemove.size(); } @@ -313,13 +317,14 @@ public class MCRecipeManager implements IRecipeManager { } } - private void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) { - ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, mirrored); + private void addShaped(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, IRecipeAction action, boolean mirrored) { + ShapedRecipe recipe = new ShapedRecipe(output, ingredients, function, action, mirrored); IRecipe irecipe = RecipeConverter.convert(recipe); MineTweakerAPI.apply(new ActionAddRecipe(irecipe, recipe)); } private class ContainerVirtual extends Container { + @Override public boolean canInteractWith(EntityPlayer var1) { return false; @@ -327,6 +332,7 @@ public class MCRecipeManager implements IRecipeManager { } private class ActionRemoveRecipes implements IUndoableAction { + private final List removingIndices; private final List removingRecipes; @@ -339,6 +345,7 @@ public class MCRecipeManager implements IRecipeManager { public void apply() { for(int i = removingIndices.size() - 1; i >= 0; i--) { recipes.remove((int) removingIndices.get(i)); + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(removingRecipes.get(i)); } } @@ -352,6 +359,7 @@ public class MCRecipeManager implements IRecipeManager { for(int i = 0; i < removingIndices.size(); i++) { int index = Math.min(recipes.size(), removingIndices.get(i)); recipes.add(index, removingRecipes.get(i)); + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(removingRecipes.get(i)); } } @@ -372,6 +380,7 @@ public class MCRecipeManager implements IRecipeManager { } private class ActionAddRecipe implements IUndoableAction { + private final IRecipe recipe; private final ICraftingRecipe craftingRecipe; @@ -386,6 +395,7 @@ public class MCRecipeManager implements IRecipeManager { if(craftingRecipe.hasTransformers()) { transformerRecipes.add(craftingRecipe); } + MineTweakerAPI.getIjeiRecipeRegistry().addRecipe(recipe); } @Override @@ -399,6 +409,7 @@ public class MCRecipeManager implements IRecipeManager { if(craftingRecipe.hasTransformers()) { transformerRecipes.remove(craftingRecipe); } + MineTweakerAPI.getIjeiRecipeRegistry().removeRecipe(recipe); } @Override diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/RecipeConverter.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/RecipeConverter.java index f83950f..1c6501e 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/RecipeConverter.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/RecipeConverter.java @@ -1,81 +1,69 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; +import minetweaker.api.item.*; import minetweaker.api.minecraft.MineTweakerMC; -import minetweaker.api.recipes.ICraftingRecipe; -import minetweaker.api.recipes.ShapedRecipe; -import minetweaker.api.recipes.ShapelessRecipe; -import minetweaker.api.recipes.UnknownRecipe; +import minetweaker.api.recipes.*; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.ShapedRecipes; -import net.minecraft.item.crafting.ShapelessRecipes; -import net.minecraftforge.oredict.ShapedOreRecipe; -import net.minecraftforge.oredict.ShapelessOreRecipe; +import net.minecraft.item.crafting.*; +import net.minecraftforge.oredict.*; -import java.util.ArrayList; -import java.util.Arrays; +import java.util.*; import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * @author Stan */ -public class RecipeConverter{ +public class RecipeConverter { + public static final int TYPE_ADVANCED = 0; public static final int TYPE_ORE = 1; public static final int TYPE_BASIC = 2; - private RecipeConverter(){ + + private RecipeConverter() { } - private static int getIngredientType(IIngredient pattern){ + private static int getIngredientType(IIngredient pattern) { Object internal = pattern.getInternal(); - if(internal == null){ + if(internal == null) { return TYPE_ADVANCED; - }else if(internal instanceof ItemStack){ + } else if(internal instanceof ItemStack) { return TYPE_BASIC; - }else{ + } else { return TYPE_ORE; } } - private static int getRecipeType(IIngredient[] ingredients){ + private static int getRecipeType(IIngredient[] ingredients) { int type = TYPE_BASIC; - for(IIngredient ingredient : ingredients){ + for(IIngredient ingredient : ingredients) { type = Math.min(type, getIngredientType(ingredient)); } return type; } - public static IRecipe convert(ShapelessRecipe recipe){ + public static IRecipe convert(ShapelessRecipe recipe) { IIngredient[] ingredients = recipe.getIngredients(); int type = getRecipeType(ingredients); - if(type == TYPE_BASIC){ + if(type == TYPE_BASIC) { ItemStack[] items = new ItemStack[ingredients.length]; - for(int i = 0; i < ingredients.length; i++){ + for(int i = 0; i < ingredients.length; i++) { items[i] = getItemStack(ingredients[i]); } return new ShapelessRecipeBasic(items, recipe); - }else if(type == TYPE_ORE){ + } else if(type == TYPE_ORE) { Object[] items = new Object[ingredients.length]; - for(int i = 0; i < ingredients.length; i++){ + for(int i = 0; i < ingredients.length; i++) { items[i] = ingredients[i].getInternal(); } return new ShapelessRecipeOre(items, recipe); - }else{ + } else { return new ShapelessRecipeAdvanced(recipe); } } - public static IRecipe convert(ShapedRecipe recipe){ + public static IRecipe convert(ShapedRecipe recipe) { IIngredient[] ingredients = recipe.getIngredients(); byte[] posx = recipe.getIngredientsX(); byte[] posy = recipe.getIngredientsY(); @@ -84,16 +72,16 @@ public class RecipeConverter{ int type = getRecipeType(ingredients); // construct recipe - if(type == TYPE_BASIC){ + if(type == TYPE_BASIC) { ItemStack[] basicIngredients = new ItemStack[recipe.getHeight() * recipe.getWidth()]; - for(int i = 0; i < ingredients.length; i++){ + for(int i = 0; i < ingredients.length; i++) { basicIngredients[posx[i] + posy[i] * recipe.getWidth()] = getItemStack(ingredients[i]); } return new ShapedRecipeBasic(basicIngredients, recipe); - }else if(type == TYPE_ORE){ + } else if(type == TYPE_ORE) { Object[] converted = new Object[recipe.getHeight() * recipe.getWidth()]; - for(int i = 0; i < ingredients.length; i++){ + for(int i = 0; i < ingredients.length; i++) { converted[posx[i] + posy[i] * recipe.getWidth()] = ingredients[i].getInternal(); } @@ -104,13 +92,13 @@ public class RecipeConverter{ int counter = 0; String[] parts = new String[recipe.getHeight()]; ArrayList rarguments = new ArrayList(); - for(int i = 0; i < recipe.getHeight(); i++){ + for(int i = 0; i < recipe.getHeight(); i++) { char[] pattern = new char[recipe.getWidth()]; - for(int j = 0; j < recipe.getWidth(); j++){ + for(int j = 0; j < recipe.getWidth(); j++) { int off = i * recipe.getWidth() + j; - if(converted[off] == null){ + if(converted[off] == null) { pattern[j] = ' '; - }else{ + } else { pattern[j] = (char) ('A' + counter); rarguments.add(pattern[j]); rarguments.add(converted[off]); @@ -123,58 +111,58 @@ public class RecipeConverter{ rarguments.addAll(0, Arrays.asList(parts)); return new ShapedRecipeOre(rarguments.toArray(), recipe); - }else{ + } else { return new ShapedRecipeAdvanced(recipe); } } - public static ICraftingRecipe toCraftingRecipe(IRecipe recipe){ + public static ICraftingRecipe toCraftingRecipe(IRecipe recipe) { IItemStack output = MineTweakerMC.getIItemStack(recipe.getRecipeOutput()); - if(recipe instanceof ShapelessRecipes){ + if(recipe instanceof ShapelessRecipes) { ShapelessRecipes shapeless = (ShapelessRecipes) recipe; IIngredient[] ingredients = new IIngredient[shapeless.recipeItems.size()]; - for(int i = 0; i < ingredients.length; i++){ + for(int i = 0; i < ingredients.length; i++) { ingredients[i] = MineTweakerMC.getIIngredient(shapeless.recipeItems.get(i)); } - return new ShapelessRecipe(output, ingredients, null); - }else if(recipe instanceof ShapedRecipes){ + return new ShapelessRecipe(output, ingredients, null, null); + } else if(recipe instanceof ShapedRecipes) { ShapedRecipes shaped = (ShapedRecipes) recipe; IIngredient[][] ingredients = new IIngredient[shaped.recipeHeight][shaped.recipeWidth]; - for(int i = 0; i < shaped.recipeHeight; i++){ - for(int j = 0; j < shaped.recipeWidth; j++){ + for(int i = 0; i < shaped.recipeHeight; i++) { + for(int j = 0; j < shaped.recipeWidth; j++) { ingredients[i][j] = MineTweakerMC.getIItemStack(shaped.recipeItems[i * shaped.recipeWidth + j]); } } - return new ShapedRecipe(output, ingredients, null, false); - }else if(recipe instanceof ShapedOreRecipe){ + return new ShapedRecipe(output, ingredients, null, null, false); + } else if(recipe instanceof ShapedOreRecipe) { ShapedOreRecipe shaped = (ShapedOreRecipe) recipe; int width = (int) Math.sqrt(recipe.getRecipeSize()); int height = recipe.getRecipeSize() / width; IIngredient[][] recipeIngredients = new IIngredient[height][width]; - for(int i = 0; i < height; i++){ - for(int j = 0; j < width; j++){ + for(int i = 0; i < height; i++) { + for(int j = 0; j < width; j++) { recipeIngredients[i][j] = MineTweakerMC.getIIngredient(shaped.getInput()[i * width + j]); } } - return new ShapedRecipe(output, recipeIngredients, null, false); - }else if(recipe instanceof ShapelessOreRecipe){ + return new ShapedRecipe(output, recipeIngredients, null, null, false); + } else if(recipe instanceof ShapelessOreRecipe) { ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe; IIngredient[] ingredients = new IIngredient[shapeless.getRecipeSize()]; - for(int i = 0; i < ingredients.length; i++){ + for(int i = 0; i < ingredients.length; i++) { ingredients[i] = MineTweakerMC.getIIngredient(shapeless.getInput().get(i)); } - return new ShapelessRecipe(output, ingredients, null); - }else{ + return new ShapelessRecipe(output, ingredients, null, null); + } else { return new UnknownRecipe(output); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeAdvanced.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeAdvanced.java index 6bde1f9..e5f1dcf 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeAdvanced.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeAdvanced.java @@ -1,12 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; -import minetweaker.api.recipes.ShapedRecipe; +import minetweaker.api.recipes.*; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; @@ -19,35 +13,41 @@ import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; * * @author Stan */ -public class ShapedRecipeAdvanced implements IRecipe{ +public class ShapedRecipeAdvanced implements IRecipe, IMTRecipe { + private final ShapedRecipe recipe; - public ShapedRecipeAdvanced(ShapedRecipe recipe){ + public ShapedRecipeAdvanced(ShapedRecipe recipe) { this.recipe = recipe; } @Override - public boolean matches(InventoryCrafting inventory, World world){ + public boolean matches(InventoryCrafting inventory, World world) { return recipe.matches(MCCraftingInventory.get(inventory)); } @Override - public ItemStack getCraftingResult(InventoryCrafting inventory){ + public ItemStack getCraftingResult(InventoryCrafting inventory) { return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy(); } @Override - public int getRecipeSize(){ + public int getRecipeSize() { return recipe.getWidth() * recipe.getHeight(); } @Override - public ItemStack getRecipeOutput(){ + public ItemStack getRecipeOutput() { return getItemStack(recipe.getOutput()); } @Override - public ItemStack[] getRemainingItems(InventoryCrafting inv){ + public ItemStack[] getRemainingItems(InventoryCrafting inv) { return new ItemStack[]{}; } + + @Override + public ICraftingRecipe getRecipe() { + return recipe; + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeBasic.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeBasic.java index 74445ce..867a44a 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeBasic.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeBasic.java @@ -1,13 +1,7 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; import minetweaker.api.item.IItemStack; -import minetweaker.api.recipes.ShapedRecipe; +import minetweaker.api.recipes.*; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.ShapedRecipes; @@ -18,27 +12,33 @@ import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * @author Stan */ -public class ShapedRecipeBasic extends ShapedRecipes{ +public class ShapedRecipeBasic extends ShapedRecipes implements IMTRecipe { + private final ShapedRecipe recipe; - public ShapedRecipeBasic(ItemStack[] basicInputs, ShapedRecipe recipe){ + public ShapedRecipeBasic(ItemStack[] basicInputs, ShapedRecipe recipe) { super(recipe.getWidth(), recipe.getHeight(), basicInputs, getItemStack(recipe.getOutput())); this.recipe = recipe; } @Override - public boolean matches(InventoryCrafting inventory, World world){ + public boolean matches(InventoryCrafting inventory, World world) { return recipe.matches(MCCraftingInventory.get(inventory)); } @Override - public ItemStack getCraftingResult(InventoryCrafting inventory){ + public ItemStack getCraftingResult(InventoryCrafting inventory) { IItemStack result = recipe.getCraftingResult(MCCraftingInventory.get(inventory)); - if(result == null){ + if(result == null) { return null; - }else{ + } else { return getItemStack(result).copy(); } } + + @Override + public ICraftingRecipe getRecipe() { + return recipe; + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeOre.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeOre.java index 6fa9d8b..ca009c5 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeOre.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapedRecipeOre.java @@ -1,12 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; -import minetweaker.api.recipes.ShapedRecipe; +import minetweaker.api.recipes.*; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -17,27 +11,33 @@ import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * @author Stan */ -public class ShapedRecipeOre extends ShapedOreRecipe{ +public class ShapedRecipeOre extends ShapedOreRecipe implements IMTRecipe { + private final ShapedRecipe recipe; - public ShapedRecipeOre(Object[] contents, ShapedRecipe recipe){ + public ShapedRecipeOre(Object[] contents, ShapedRecipe recipe) { super(getItemStack(recipe.getOutput()), contents); this.recipe = recipe; } @Override - public boolean matches(InventoryCrafting inventory, World world){ + public boolean matches(InventoryCrafting inventory, World world) { return recipe.matches(MCCraftingInventory.get(inventory)); } @Override - public ItemStack getCraftingResult(InventoryCrafting inventory){ - if(recipe != null){ - if(recipe.getCraftingResult(MCCraftingInventory.get(inventory)) != null){ + public ItemStack getCraftingResult(InventoryCrafting inventory) { + if(recipe != null) { + if(recipe.getCraftingResult(MCCraftingInventory.get(inventory)) != null) { return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy(); } } return null; } + + @Override + public ICraftingRecipe getRecipe() { + return recipe; + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeAdvanced.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeAdvanced.java index c0b607b..214ea2b 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeAdvanced.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeAdvanced.java @@ -1,12 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; -import minetweaker.api.recipes.ShapelessRecipe; +import minetweaker.api.recipes.*; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; @@ -17,35 +11,41 @@ import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * @author Stan */ -public class ShapelessRecipeAdvanced implements IRecipe{ +public class ShapelessRecipeAdvanced implements IRecipe, IMTRecipe { + private final ShapelessRecipe recipe; - public ShapelessRecipeAdvanced(ShapelessRecipe recipe){ + public ShapelessRecipeAdvanced(ShapelessRecipe recipe) { this.recipe = recipe; } @Override - public boolean matches(InventoryCrafting inventory, World world){ + public boolean matches(InventoryCrafting inventory, World world) { return recipe.matches(MCCraftingInventory.get(inventory)); } @Override - public ItemStack getCraftingResult(InventoryCrafting inventory){ + public ItemStack getCraftingResult(InventoryCrafting inventory) { return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy(); } @Override - public int getRecipeSize(){ + public int getRecipeSize() { return recipe.getSize(); } @Override - public ItemStack getRecipeOutput(){ + public ItemStack getRecipeOutput() { return getItemStack(recipe.getOutput()); } @Override - public ItemStack[] getRemainingItems(InventoryCrafting inv){ + public ItemStack[] getRemainingItems(InventoryCrafting inv) { return new ItemStack[]{}; } + + @Override + public ICraftingRecipe getRecipe() { + return recipe; + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeBasic.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeBasic.java index 113f8ee..e2c4b16 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeBasic.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeBasic.java @@ -1,12 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; -import minetweaker.api.recipes.ShapelessRecipe; +import minetweaker.api.recipes.*; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.ShapelessRecipes; @@ -19,22 +13,31 @@ import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * @author Stan */ -public class ShapelessRecipeBasic extends ShapelessRecipes{ +public class ShapelessRecipeBasic extends ShapelessRecipes implements IMTRecipe { + private final ShapelessRecipe recipe; - public ShapelessRecipeBasic(ItemStack[] ingredients, ShapelessRecipe recipe){ + public ShapelessRecipeBasic(ItemStack[] ingredients, ShapelessRecipe recipe) { super(getItemStack(recipe.getOutput()), Arrays.asList(ingredients)); this.recipe = recipe; } @Override - public boolean matches(InventoryCrafting inventory, World world){ + public boolean matches(InventoryCrafting inventory, World world) { return recipe.matches(MCCraftingInventory.get(inventory)); } @Override - public ItemStack getCraftingResult(InventoryCrafting inventory){ - return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy(); + public ItemStack getCraftingResult(InventoryCrafting inventory) { + if(recipe.getCraftingResult(MCCraftingInventory.get(inventory)) != null) { + return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy(); + } + return null; + } + + @Override + public ICraftingRecipe getRecipe() { + return recipe; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeOre.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeOre.java index 4a4ce37..18280d5 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeOre.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/recipes/ShapelessRecipeOre.java @@ -1,12 +1,6 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.recipes; -import minetweaker.api.recipes.ShapelessRecipe; +import minetweaker.api.recipes.*; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -17,22 +11,28 @@ import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * @author Stan */ -public class ShapelessRecipeOre extends ShapelessOreRecipe{ +public class ShapelessRecipeOre extends ShapelessOreRecipe implements IMTRecipe { + private final ShapelessRecipe recipe; - public ShapelessRecipeOre(Object[] ingredients, ShapelessRecipe recipe){ + public ShapelessRecipeOre(Object[] ingredients, ShapelessRecipe recipe) { super(getItemStack(recipe.getOutput()), ingredients); this.recipe = recipe; } @Override - public boolean matches(InventoryCrafting inventory, World world){ + public boolean matches(InventoryCrafting inventory, World world) { return recipe.matches(MCCraftingInventory.get(inventory)); } @Override - public ItemStack getCraftingResult(InventoryCrafting inventory){ + public ItemStack getCraftingResult(InventoryCrafting inventory) { return getItemStack(recipe.getCraftingResult(MCCraftingInventory.get(inventory))).copy(); } + + @Override + public ICraftingRecipe getRecipe() { + return recipe; + } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/MCServer.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/MCServer.java index e44282e..d5e9de8 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/MCServer.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/MCServer.java @@ -1,42 +1,28 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.server; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.player.IPlayer; -import minetweaker.api.server.AbstractServer; -import minetweaker.api.server.ICommandFunction; -import minetweaker.api.server.ICommandTabCompletion; -import minetweaker.api.server.ICommandValidator; +import minetweaker.api.server.*; import minetweaker.mc1102.MineTweakerMod; -import minetweaker.mc1102.player.CommandBlockPlayer; -import minetweaker.mc1102.player.RconPlayer; -import net.minecraft.command.CommandException; -import net.minecraft.command.CommandHandler; -import net.minecraft.command.ICommand; -import net.minecraft.command.ICommandSender; +import minetweaker.mc1102.player.*; +import net.minecraft.command.*; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.rcon.RConConsoleSource; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.management.UserListOps; import net.minecraft.tileentity.CommandBlockBaseLogic; import net.minecraft.util.math.BlockPos; import stanhebben.zenscript.annotations.Optional; -import java.util.Arrays; -import java.util.List; +import javax.annotation.Nullable; +import java.util.*; /** * @author Stan */ public class MCServer extends AbstractServer { + private final MinecraftServer server; public MCServer(MinecraftServer server) { @@ -46,22 +32,22 @@ public class MCServer extends AbstractServer { private static IPlayer getPlayer(ICommandSender commandSender) { if(commandSender instanceof EntityPlayer) { return MineTweakerMC.getIPlayer((EntityPlayer) commandSender); - } else if(commandSender instanceof DedicatedServer) { - return ServerPlayer.INSTANCE; } else if(commandSender instanceof RConConsoleSource) { return new RconPlayer(commandSender); } else if(commandSender instanceof CommandBlockBaseLogic) { return new CommandBlockPlayer(commandSender); + } else if(commandSender.getName().equals("Server")) { + return ServerPlayer.INSTANCE; } else { - System.out.println("Unsupported command sender: " + commandSender); + System.out.println("Unsupported command sender: " + commandSender + " defaulting to server player!"); System.out.println("player name: " + commandSender.getName()); - return null; + System.out.println("Please report to mod author if this is incorrect!"); + return ServerPlayer.INSTANCE; } } @Override public void addCommand(String name, String usage, String[] aliases, ICommandFunction function, @Optional ICommandValidator validator, @Optional ICommandTabCompletion completion) { - ICommand command = new MCCommand(name, usage, aliases, function, validator, completion); MineTweakerAPI.apply(new AddCommandAction(command)); } @@ -72,7 +58,7 @@ public class MCServer extends AbstractServer { return true; UserListOps ops = MineTweakerMod.server.getPlayerList().getOppedPlayers(); - if(server.isDedicatedServer() && ops != null) { + if(server != null && server.isDedicatedServer() && ops != null) { //TODO figure if this is correct // return ops.func_152690_d() || ops.func_152700_a(player.getName()) != null || player instanceof RconPlayer; return ops.isEmpty() || ops.getGameProfileFromName(player.getName()) != null || player instanceof RconPlayer; @@ -87,6 +73,7 @@ public class MCServer extends AbstractServer { } private class MCCommand implements ICommand { + private final String name; private final String usage; private final List aliases; @@ -104,17 +91,17 @@ public class MCServer extends AbstractServer { } @Override - public String getCommandName() { + public String getName() { return name; } @Override - public String getCommandUsage(ICommandSender var1) { + public String getUsage(ICommandSender var1) { return usage; } @Override - public List getCommandAliases() { + public List getAliases() { return aliases; } @@ -131,9 +118,9 @@ public class MCServer extends AbstractServer { return validator.canExecute(getPlayer(sender)); } } - + @Override - public List getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) { + public List getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) { if(completion != null) { return Arrays.asList(completion.getTabCompletionOptions(args, getPlayer(sender))); } else { @@ -148,11 +135,12 @@ public class MCServer extends AbstractServer { @Override public int compareTo(ICommand o) { - return 0; + return this.getName().compareTo(o.getName()); } } private class AddCommandAction implements IUndoableAction { + private final ICommand command; public AddCommandAction(ICommand command) { @@ -180,13 +168,13 @@ public class MCServer extends AbstractServer { public String describe() { CommandHandler ch = (CommandHandler) MineTweakerMod.server.getCommandManager(); if(!ch.getCommands().containsValue(command)) - return "Adding command " + command.getCommandName(); + return "Adding command " + command.getName(); return ""; } @Override public String describeUndo() { - return "tried to remove command: " + command.getCommandName() + " failed. THIS IS NOT AN ERROR!"; + return "tried to remove command: " + command.getName() + " failed. THIS IS NOT AN ERROR!"; } @Override diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/ServerPlayer.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/ServerPlayer.java index f4413e5..36de847 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/ServerPlayer.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/server/ServerPlayer.java @@ -1,117 +1,124 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.server; import minetweaker.api.chat.IChatMessage; import minetweaker.api.data.IData; import minetweaker.api.item.IItemStack; import minetweaker.api.player.IPlayer; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.*; import net.minecraftforge.fml.server.FMLServerHandler; import java.awt.*; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.*; import java.io.IOException; import java.net.URI; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; /** * @author Stan */ -public class ServerPlayer implements IPlayer{ +public class ServerPlayer implements IPlayer { + public static final ServerPlayer INSTANCE = new ServerPlayer(); - private ServerPlayer(){ + private ServerPlayer() { } @Override - public String getId(){ + public String getId() { return "server"; } @Override - public String getName(){ + public String getName() { return "Server"; } @Override - public IData getData(){ + public IData getData() { // TODO: implement return null; } - + @Override - public void update(IData data){ + public int getXP() { + return 0; + } + + @Override + public void setXP(int xp) { + + } + + @Override + public void removeXP(int xp) { + + } + + @Override + public void update(IData data) { // TODO: implement } @Override - public void sendChat(IChatMessage message){ - FMLServerHandler.instance().getServer().addChatMessage((ITextComponent) message.getInternal()); + public void sendChat(IChatMessage message) { + FMLServerHandler.instance().getServer().sendMessage((ITextComponent) message.getInternal()); } @Override - public void sendChat(String message){ - FMLServerHandler.instance().getServer().addChatMessage(new TextComponentString(message)); + public void sendChat(String message) { + FMLServerHandler.instance().getServer().sendMessage(new TextComponentString(message)); } @Override - public int getHotbarSize(){ + public int getHotbarSize() { return 0; } @Override - public IItemStack getHotbarStack(int i){ + public IItemStack getHotbarStack(int i) { return null; } @Override - public int getInventorySize(){ + public int getInventorySize() { return 0; } @Override - public IItemStack getInventoryStack(int i){ + public IItemStack getInventoryStack(int i) { return null; } @Override - public IItemStack getCurrentItem(){ + public IItemStack getCurrentItem() { return null; } @Override - public boolean isCreative(){ + public boolean isCreative() { return true; } @Override - public boolean isAdventure(){ + public boolean isAdventure() { return false; } @Override - public void openBrowser(String url){ - if(Desktop.isDesktopSupported()){ - try{ + public void openBrowser(String url) { + if(Desktop.isDesktopSupported()) { + try { Desktop.getDesktop().browse(URI.create(url)); - }catch(IOException ex){ + } catch(IOException ex) { Logger.getLogger(ServerPlayer.class.getName()).log(Level.SEVERE, null, ex); } } } @Override - public void copyToClipboard(String value){ - if(Desktop.isDesktopSupported()){ + public void copyToClipboard(String value) { + if(Desktop.isDesktopSupported()) { StringSelection stringSelection = new StringSelection(value); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); @@ -119,7 +126,7 @@ public class ServerPlayer implements IPlayer{ } @Override - public void give(IItemStack stack){ + public void give(IItemStack stack) { } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerHacks.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerHacks.java index f5b4189..37bad87 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerHacks.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerHacks.java @@ -1,41 +1,22 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.util; -import com.google.common.collect.BiMap; import minetweaker.MineTweakerAPI; import minetweaker.api.item.WeightedItemStack; import minetweaker.api.minecraft.MineTweakerMC; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.SlotCrafting; +import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.*; import net.minecraft.server.MinecraftServer; import net.minecraft.util.WeightedRandom; -import net.minecraft.util.text.translation.I18n; -import net.minecraft.util.text.translation.LanguageMap; +import net.minecraft.util.text.translation.*; import net.minecraftforge.common.ForgeHooks; -import net.minecraftforge.fml.common.registry.EntityRegistry; -import net.minecraftforge.oredict.OreDictionary; -import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.*; import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.lang.reflect.*; +import java.util.*; +import java.util.logging.*; /** * Common class for all runtime hacks (stuff requiring reflection). It is not @@ -44,7 +25,8 @@ import java.util.logging.Logger; * * @author Stan Hebben */ -public class MineTweakerHacks{ +public class MineTweakerHacks { + private static final Field NBTTAGLIST_TAGLIST; private static final Field OREDICTIONARY_IDTOSTACK; private static final Field OREDICTIONARY_IDTOSTACKUN; @@ -53,11 +35,10 @@ public class MineTweakerHacks{ private static final Field INVENTORYCRAFTING_EVENTHANDLER; private static final Field SLOTCRAFTING_PLAYER; - private static final Field ENTITYREGISTRY_CLASSREGISTRATIONS; private static final Field SEEDENTRY_SEED; private static final Constructor SEEDENTRY_CONSTRUCTOR; - static{ + static { NBTTAGLIST_TAGLIST = getField(NBTTagList.class, MineTweakerObfuscation.NBTTAGLIST_TAGLIST); OREDICTIONARY_IDTOSTACK = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_IDTOSTACK); OREDICTIONARY_IDTOSTACKUN = getField(OreDictionary.class, MineTweakerObfuscation.OREDICTIONARY_IDTOSTACKUN); @@ -66,96 +47,84 @@ public class MineTweakerHacks{ INVENTORYCRAFTING_EVENTHANDLER = getField(InventoryCrafting.class, MineTweakerObfuscation.INVENTORYCRAFTING_EVENTHANDLER); SLOTCRAFTING_PLAYER = getField(SlotCrafting.class, MineTweakerObfuscation.SLOTCRAFTING_PLAYER); - ENTITYREGISTRY_CLASSREGISTRATIONS = getField(EntityRegistry.class, "entityClassRegistrations"); Class forgeSeedEntry = null; - try{ + try { forgeSeedEntry = (Class) Class.forName("net.minecraftforge.common.ForgeHooks$SeedEntry"); - }catch(ClassNotFoundException ex){ + } catch(ClassNotFoundException ex) { } SEEDENTRY_SEED = getField(forgeSeedEntry, "seed"); Constructor seedEntryConstructor = null; - try{ + try { seedEntryConstructor = forgeSeedEntry.getConstructor(ItemStack.class, int.class); seedEntryConstructor.setAccessible(true); - }catch(NoSuchMethodException ex){ - Logger.getLogger(MineTweakerHacks.class.getName()).log(Level.SEVERE, null, ex); - }catch(SecurityException ex){ + } catch(NoSuchMethodException | SecurityException ex) { Logger.getLogger(MineTweakerHacks.class.getName()).log(Level.SEVERE, null, ex); } SEEDENTRY_CONSTRUCTOR = seedEntryConstructor; } - private MineTweakerHacks(){ + private MineTweakerHacks() { } - public static BiMap, EntityRegistry.EntityRegistration> getEntityClassRegistrations(){ - try{ - return (BiMap, EntityRegistry.EntityRegistration>) ENTITYREGISTRY_CLASSREGISTRATIONS.get(EntityRegistry.instance()); - }catch(IllegalArgumentException ex){ + + public static List getTagList(NBTTagList list) { + if(NBTTAGLIST_TAGLIST == null) { return null; - }catch(IllegalAccessException ex){ + } + try { + return (List) NBTTAGLIST_TAGLIST.get(list); + } catch(IllegalArgumentException ex) { + return null; + } catch(IllegalAccessException ex) { return null; } } - public static List getTagList(NBTTagList list){ - if(NBTTAGLIST_TAGLIST == null){ - return null; - } - try{ - return (List) NBTTAGLIST_TAGLIST.get(list); - }catch(IllegalArgumentException ex){ - return null; - }catch(IllegalAccessException ex){ - return null; - } - } - - public static List getSeeds(){ + public static List getSeeds() { return getPrivateStaticObject(ForgeHooks.class, "seedList"); } - public static Map getTranslations(){ + public static Map getTranslations() { return getPrivateObject(getPrivateStaticObject(I18n.class, "localizedName", "field_74839_a"), "languageList", "field_74816_c"); } - public static List> getOreIdStacks(){ - try{ + public static List> getOreIdStacks() { + try { return (List>) OREDICTIONARY_IDTOSTACK.get(null); - }catch(IllegalAccessException ex){ + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("ERROR - could not load ore dictionary stacks!"); return null; } } - public static List> getOreIdStacksUn(){ - try{ + public static List> getOreIdStacksUn() { + try { return (List>) OREDICTIONARY_IDTOSTACKUN.get(null); - }catch(IllegalAccessException ex){ + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("ERROR - could not load ore dictionary stacks!"); return null; } } - public static File getAnvilFile(MinecraftServer server){ - try{ + public static File getAnvilFile(MinecraftServer server) { + try { return (File) MINECRAFTSERVER_ANVILFILE.get(server); - }catch(IllegalAccessException ex){ + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("could not load anvil file!"); return null; } } - public static File getWorldDirectory(MinecraftServer server){ - if(server.isDedicatedServer()){ + public static File getWorldDirectory(MinecraftServer server) { + if(server.isDedicatedServer()) { return server.getFile("world"); - }else{ + } else { File worldsDir = getAnvilFile(server); if(worldsDir == null) return null; @@ -164,28 +133,28 @@ public class MineTweakerHacks{ } } - public static int getShapedOreRecipeWidth(ShapedOreRecipe recipe){ - try{ + public static int getShapedOreRecipeWidth(ShapedOreRecipe recipe) { + try { return SHAPEDORERECIPE_WIDTH.getInt(recipe); - }catch(IllegalAccessException ex){ + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("could not load anvil file!"); return 3; } } - public static Container getCraftingContainer(InventoryCrafting inventory){ - try{ + public static Container getCraftingContainer(InventoryCrafting inventory) { + try { return (Container) INVENTORYCRAFTING_EVENTHANDLER.get(inventory); - }catch(IllegalAccessException ex){ + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("could not get inventory eventhandler"); return null; } } - public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot){ - try{ + public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) { + try { return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot); - }catch(IllegalAccessException ex){ + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("could not get inventory eventhandler"); return null; } @@ -195,50 +164,39 @@ public class MineTweakerHacks{ try { Field field = getField(LanguageMap.class, MineTweakerObfuscation.LANGUAGEMAP_INSTANCE); return (LanguageMap) field.get(null); - } catch (IllegalAccessException ex) { + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("could not get LanguageMap"); return null; } } - public static ItemStack getSeedEntrySeed(Object entry){ - try{ + public static ItemStack getSeedEntrySeed(Object entry) { + try { return (ItemStack) SEEDENTRY_SEED.get(entry); - }catch(IllegalAccessException ex){ + } catch(IllegalAccessException ex) { MineTweakerAPI.logError("could not get SeedEntry seed"); return null; } } - - public static WeightedRandom.Item constructSeedEntry(WeightedItemStack stack){ - try{ + public static WeightedRandom.Item constructSeedEntry(WeightedItemStack stack) { + try { return SEEDENTRY_CONSTRUCTOR.newInstance(MineTweakerMC.getItemStack(stack.getStack()), (int) stack.getChance()); - }catch(InstantiationException ex){ - MineTweakerAPI.logError("could not construct SeedEntry"); - }catch(IllegalAccessException ex){ - MineTweakerAPI.logError("could not construct SeedEntry"); - }catch(IllegalArgumentException ex){ - MineTweakerAPI.logError("could not construct SeedEntry"); - }catch(InvocationTargetException ex){ + } catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { MineTweakerAPI.logError("could not construct SeedEntry"); } return null; } - public static T getPrivateStaticObject(Class cls, String... names){ - for(String name : names){ - try{ + public static T getPrivateStaticObject(Class cls, String... names) { + for(String name : names) { + try { Field field = cls.getDeclaredField(name); field.setAccessible(true); return (T) field.get(null); - }catch(NoSuchFieldException ex){ - - }catch(SecurityException ex){ - - }catch(IllegalAccessException ex){ + } catch(NoSuchFieldException | SecurityException | IllegalAccessException ignored) { } } @@ -246,18 +204,14 @@ public class MineTweakerHacks{ return null; } - public static T getPrivateObject(Object object, String... names){ + public static T getPrivateObject(Object object, String... names) { Class cls = object.getClass(); - for(String name : names){ - try{ + for(String name : names) { + try { Field field = cls.getDeclaredField(name); field.setAccessible(true); return (T) field.get(object); - }catch(NoSuchFieldException ex){ - - }catch(SecurityException ex){ - - }catch(IllegalAccessException ex){ + } catch(NoSuchFieldException | SecurityException | IllegalAccessException ignored) { } } @@ -269,14 +223,13 @@ public class MineTweakerHacks{ // ### Private Methods ### // ####################### - private static Field getField(Class cls, String... names){ - for(String name : names){ - try{ + private static Field getField(Class cls, String... names) { + for(String name : names) { + try { Field field = cls.getDeclaredField(name); field.setAccessible(true); return field; - }catch(NoSuchFieldException ex){ - }catch(SecurityException ex){ + } catch(NoSuchFieldException | SecurityException ignored) { } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerObfuscation.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerObfuscation.java index 177fa9e..805b0ea 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerObfuscation.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerObfuscation.java @@ -1,23 +1,19 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.util; /** * @author Stanneke */ -public class MineTweakerObfuscation{ +public class MineTweakerObfuscation { + public static final String[] NBTTAGLIST_TAGLIST = {"tagList", "field_74747_a"}; public static final String[] CRAFTINGMANAGER_RECIPES = {"recipes", "field_77597_b"}; public static final String[] OREDICTIONARY_IDTOSTACK = {"idToStack"}; public static final String[] OREDICTIONARY_IDTOSTACKUN = {"idToStackUn"}; public static final String[] MINECRAFTSERVER_ANVILFILE = {"anvilFile", "field_71308_o"}; public static final String[] INVENTORYCRAFTING_EVENTHANDLER = {"eventHandler", "field_70465_c"}; - public static final String[] SLOTCRAFTING_PLAYER = {"thePlayer", "field_75238_b"}; + public static final String[] SLOTCRAFTING_PLAYER = {"player", "field_75238_b"}; public static final String[] LANGUAGEMAP_INSTANCE = {"instance", "field_74817_a"}; - private MineTweakerObfuscation(){ + + private MineTweakerObfuscation() { } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerPlatformUtils.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerPlatformUtils.java index e23777c..2fd98db 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerPlatformUtils.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/util/MineTweakerPlatformUtils.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.util; import net.minecraft.entity.EntityLivingBase; @@ -14,32 +8,33 @@ import net.minecraftforge.fml.relauncher.Side; /** * @author Stan */ -public class MineTweakerPlatformUtils{ - private MineTweakerPlatformUtils(){ +public class MineTweakerPlatformUtils { + + private MineTweakerPlatformUtils() { } - public static Class getLivingEntityClass(String entityClassName){ - try{ + public static Class getLivingEntityClass(String entityClassName) { + try { Class entityClass = Class.forName(entityClassName); - if(!EntityLivingBase.class.isAssignableFrom(entityClass)){ + if(!EntityLivingBase.class.isAssignableFrom(entityClass)) { throw new RuntimeException("Not an entity class: " + entityClassName); } return (Class) entityClass; - }catch(ClassNotFoundException ex){ + } catch(ClassNotFoundException ex) { throw new RuntimeException("entity class not found: " + entityClassName); } } - public static String getLanguage(){ + public static String getLanguage() { return FMLCommonHandler.instance().getSide() == Side.SERVER ? null : FMLClientHandler.instance().getCurrentLanguage(); } - public static boolean isLanguageActive(String lang){ + public static boolean isLanguageActive(String lang) { String current = getLanguage(); return current != null && current.equals(lang); } - public static boolean isClient(){ + public static boolean isClient() { return FMLCommonHandler.instance().getSide() == Side.CLIENT; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCSeedRegistry.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCSeedRegistry.java index f360354..1a98bb7 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCSeedRegistry.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCSeedRegistry.java @@ -1,145 +1,133 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.vanilla; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import minetweaker.api.item.WeightedItemStack; +import minetweaker.*; +import minetweaker.api.item.*; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.vanilla.ISeedRegistry; import minetweaker.mc1102.util.MineTweakerHacks; import net.minecraft.item.ItemStack; import net.minecraft.util.WeightedRandom; -import java.util.ArrayList; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * @author Stan */ -public class MCSeedRegistry implements ISeedRegistry{ +public class MCSeedRegistry implements ISeedRegistry { + private static final List SEEDS = MineTweakerHacks.getSeeds(); @Override - public void addSeed(WeightedItemStack item){ + public void addSeed(WeightedItemStack item) { MineTweakerAPI.apply(new AddSeedAction(item)); } @Override - public void removeSeed(IIngredient pattern){ + public void removeSeed(IIngredient pattern) { MineTweakerAPI.apply(new RemoveSeedAction(pattern)); } @Override - public List getSeeds(){ + public List getSeeds() { List entries = (List) SEEDS; - List results = new ArrayList(); - for(WeightedRandom.Item entry : entries){ - results.add(new WeightedItemStack(MineTweakerMC.getIItemStack(MineTweakerHacks.getSeedEntrySeed(entry)), entry.itemWeight)); - } - return results; + return entries.stream().map(entry -> new WeightedItemStack(MineTweakerMC.getIItemStack(MineTweakerHacks.getSeedEntrySeed(entry)), entry.itemWeight)).collect(Collectors.toList()); } // ###################### // ### Action classes ### // ###################### - private static class AddSeedAction implements IUndoableAction{ + private static class AddSeedAction implements IUndoableAction { + private final IItemStack item; private final WeightedRandom.Item entry; - public AddSeedAction(WeightedItemStack item){ + public AddSeedAction(WeightedItemStack item) { this.item = item.getStack(); entry = MineTweakerHacks.constructSeedEntry(item); } @Override - public void apply(){ + public void apply() { SEEDS.add(entry); } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ + public void undo() { SEEDS.remove(entry); } @Override - public String describe(){ + public String describe() { return "Adding seed entry " + item; } @Override - public String describeUndo(){ + public String describeUndo() { return "Removing seed entry " + item; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } - private static class RemoveSeedAction implements IUndoableAction{ + private static class RemoveSeedAction implements IUndoableAction { + private final IIngredient pattern; private final List removed; - public RemoveSeedAction(IIngredient ingredient){ + public RemoveSeedAction(IIngredient ingredient) { this.pattern = ingredient; - removed = new ArrayList(); + removed = new ArrayList<>(); } @Override - public void apply(){ + public void apply() { removed.clear(); - for(Object entry : SEEDS){ + for(Object entry : SEEDS) { ItemStack itemStack = MineTweakerHacks.getSeedEntrySeed(entry); - if(pattern.matches(MineTweakerMC.getIItemStack(itemStack))){ + if(pattern.matches(MineTweakerMC.getIItemStack(itemStack))) { removed.add(entry); } } - for(Object entry : removed){ + for(Object entry : removed) { SEEDS.remove(entry); } } @Override - public boolean canUndo(){ + public boolean canUndo() { return true; } @Override - public void undo(){ - for(Object entry : removed){ - SEEDS.add(entry); - } + public void undo() { + SEEDS.addAll(removed); } @Override - public String describe(){ + public String describe() { return "Removing seeds " + pattern; } @Override - public String describeUndo(){ + public String describeUndo() { return "Restoring seeds " + pattern + " (" + removed.size() + " entries)"; } @Override - public Object getOverrideKey(){ + public Object getOverrideKey() { return null; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCVanilla.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCVanilla.java index 6a1fc3f..f6d86e8 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCVanilla.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/vanilla/MCVanilla.java @@ -1,29 +1,22 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.vanilla; -import minetweaker.api.vanilla.ILootRegistry; -import minetweaker.api.vanilla.ISeedRegistry; -import minetweaker.api.vanilla.IVanilla; +import minetweaker.api.vanilla.*; /** * @author Stan */ -public class MCVanilla implements IVanilla{ -// private final MCLootRegistry lootRegistry = new MCLootRegistry(); +public class MCVanilla implements IVanilla { + + // private final MCLootRegistry lootRegistry = new MCLootRegistry(); private final MCSeedRegistry seedRegistry = new MCSeedRegistry(); @Override - public ILootRegistry getLoot(){ + public ILootRegistry getLoot() { return null; } @Override - public ISeedRegistry getSeeds(){ + public ISeedRegistry getSeeds() { return seedRegistry; } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCBiome.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCBiome.java index 635f25f..882199f 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCBiome.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCBiome.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.world; import minetweaker.api.world.IBiome; @@ -12,15 +6,16 @@ import net.minecraft.world.biome.Biome; /** * @author Stan */ -public class MCBiome implements IBiome{ +public class MCBiome implements IBiome { + private final Biome biome; - public MCBiome(Biome biome){ + public MCBiome(Biome biome) { this.biome = biome; } @Override - public String getName(){ + public String getName() { return biome.getBiomeName(); } } diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCDimension.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCDimension.java index 5b47c57..87daca3 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCDimension.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/world/MCDimension.java @@ -1,9 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mc1102.world; import minetweaker.api.block.IBlock; @@ -15,30 +9,31 @@ import net.minecraft.world.World; /** * @author Stan */ -public class MCDimension implements IDimension{ +public class MCDimension implements IDimension { + private final World world; - public MCDimension(World world){ + public MCDimension(World world) { this.world = world; } @Override - public boolean isDay(){ + public boolean isDay() { return world.isDaytime(); } @Override - public int getBrightness(int x, int y, int z){ + public int getBrightness(int x, int y, int z) { return world.getLight(new BlockPos(x, y, z)); } @Override - public IDimension getDimension(){ + public IDimension getDimension() { return this; } @Override - public IBlock getBlock(int x, int y, int z){ + public IBlock getBlock(int x, int y, int z) { return MineTweakerMC.getBlock(world, x, y, z); } } diff --git a/MineTweaker3-MC1102-Main/src/main/resources/mcmod.info b/MineTweaker3-MC1102-Main/src/main/resources/mcmod.info index b4de473..83997f6 100644 --- a/MineTweaker3-MC1102-Main/src/main/resources/mcmod.info +++ b/MineTweaker3-MC1102-Main/src/main/resources/mcmod.info @@ -1,16 +1,18 @@ [ -{ - "modid": "MineTweaker3", - "name": "MineTweaker 3", - "version": "${version}", - "mcversion": "${mcversion}", - "description": "Customize your minecraft experience!", - "credits": "Created By Stan Hebben", - "logoFile": "assets/minetweaker/logo.png", - "url": "http://minetweaker3.powerofbytes.com", - "authorList": [ "Stan Hebben" ], - "parent": "", - "screenshots": [], - "dependencies": [] -} + { + "modid": "MineTweaker3", + "name": "MineTweaker 3", + "version": "${version}", + "mcversion": "${mcversion}", + "description": "Customize your minecraft experience!", + "credits": "Created By Stan Hebben", + "logoFile": "assets/minetweaker/logo.png", + "url": "http://minetweaker3.powerofbytes.com", + "authorList": [ + "Stan Hebben" + ], + "parent": "", + "screenshots": [], + "dependencies": [] + } ] diff --git a/MineTweaker3-MC1102-Mod-IC2/build.gradle b/MineTweaker3-MC1102-Mod-IC2/build.gradle index 57e41bd..23969c2 100644 --- a/MineTweaker3-MC1102-Mod-IC2/build.gradle +++ b/MineTweaker3-MC1102-Mod-IC2/build.gradle @@ -1,7 +1,6 @@ import minetweaker.tasks.RegisterZenClassesTask; - buildscript { repositories { mavenCentral() @@ -13,10 +12,10 @@ buildscript { name = "sonatype" url = "https://oss.sonatype.org/content/repositories/snapshots/" } - + } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' } } apply plugin: 'net.minecraftforge.gradle.forge' @@ -28,23 +27,23 @@ version = "1.10.2-" + ext.mineTweakerVersion archivesBaseName = project.projectDir.name minecraft { - version = forgeVersion1102 - runDir = "eclipse" - mappings = "snapshot_20160518" - useDepAts = true + version = forgeVersion1102 + runDir = "eclipse" + mappings = "stable_29" + useDepAts = true } dependencies { - compile project(':ZenScript') - compile project(':MineTweaker3-API') - compile project(':MineTweaker3-MC1102-Main') - compile files('libs/industrialcraft-2-2.5.63-ex19-dev.jar') + compile project(':ZenScript') + compile project(':MineTweaker3-API') + compile project(':MineTweaker3-MC1102-Main') + compile files('libs/industrialcraft-2-2.5.63-ex19-dev.jar') } task makeRegistry(type: RegisterZenClassesTask) { - inputDir = file('build/classes/main') - outputDir = file('build/classes/main') - className = 'minetweaker.mods.ic2.ClassRegistry' + inputDir = file('build/classes/main') + outputDir = file('build/classes/main') + className = 'minetweaker.mods.ic2.ClassRegistry' } tasks.jar.dependsOn(makeRegistry) diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2BracketHandler.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2BracketHandler.java index b8f842a..8f9f485 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2BracketHandler.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2BracketHandler.java @@ -1,20 +1,14 @@ package minetweaker.mods.ic2; import ic2.api.item.IC2Items; -import java.util.List; -import minetweaker.IBracketHandler; -import minetweaker.MineTweakerAPI; -import minetweaker.annotations.BracketHandler; -import minetweaker.annotations.ModOnly; +import minetweaker.*; +import minetweaker.annotations.*; import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; import stanhebben.zenscript.ZenTokener; import stanhebben.zenscript.compiler.IEnvironmentGlobal; -import stanhebben.zenscript.expression.ExpressionInt; -import stanhebben.zenscript.expression.ExpressionCallStatic; -import stanhebben.zenscript.expression.ExpressionString; +import stanhebben.zenscript.expression.*; import stanhebben.zenscript.expression.partial.IPartialExpression; import stanhebben.zenscript.parser.Token; import stanhebben.zenscript.symbols.IZenSymbol; @@ -22,82 +16,80 @@ import stanhebben.zenscript.type.ZenType; import stanhebben.zenscript.type.natives.IJavaMethod; import stanhebben.zenscript.util.ZenPosition; +import java.util.List; + +import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; + /** * Makes a ic2-item specific item syntax available in the form <item-ic2:name[:meta]>. - * + * * @author Stan Hebben */ @BracketHandler @ModOnly("IC2") public class IC2BracketHandler implements IBracketHandler { - public static IItemStack getItem(String name, int meta) { - ItemStack stack = IC2Items.getItem(name); - stack.setItemDamage(meta); - return getIItemStack(stack); - } - - private final IJavaMethod method; - - public IC2BracketHandler() { - method = MineTweakerAPI.getJavaMethod(IC2BracketHandler.class, "getItem", String.class, int.class); - } - - @Override - public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) { - if (tokens.size() >= 5) { - if (tokens.get(0).getValue().equals("ic2") - && tokens.get(1).getValue().equals("-") - && tokens.get(2).getValue().equals("item") - && tokens.get(3).getValue().equals(":")) { - String name = tokens.get(4).getValue(); - int meta = 0; - if (tokens.size() > 6 && tokens.get(5).getValue().equals(":")) { - if (tokens.get(6).getType() == ZenTokener.T_INTVALUE) { - meta = Integer.parseInt(tokens.get(6).getValue()); - } else if (tokens.get(6).getValue().equals("*")) { - meta = OreDictionary.WILDCARD_VALUE; - } else { - MineTweakerAPI.logError("Not a valid meta value: " + tokens.get(6).getValue()); - } - } - ItemStack item = IC2Items.getItem(name); - if (item == null) { - MineTweakerAPI.logError("Not a valid IC2 item: " + name); - return null; - } else { - return new ItemReferenceSymbol(environment, name, meta); - } - } else { - return null; - } - } else { - return null; - } - } - - // ############################# - // ### Private inner classes ### - // ############################# - - private class ItemReferenceSymbol implements IZenSymbol { - private final IEnvironmentGlobal environment; - private final String name; - private final int meta; - - public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) { - this.environment = environment; - this.name = name; - this.meta = meta; - } - - @Override - public IPartialExpression instance(ZenPosition position) { - return new ExpressionCallStatic( - position, - environment, - method, - new ExpressionString(position, name), - new ExpressionInt(position, meta, ZenType.INT)); - } - } + + private final IJavaMethod method; + + public IC2BracketHandler() { + method = MineTweakerAPI.getJavaMethod(IC2BracketHandler.class, "getItem", String.class, int.class); + } + + public static IItemStack getItem(String name, int meta) { + ItemStack stack = IC2Items.getItem(name); + stack.setItemDamage(meta); + return getIItemStack(stack); + } + + @Override + public IZenSymbol resolve(IEnvironmentGlobal environment, List tokens) { + if(tokens.size() >= 5) { + if(tokens.get(0).getValue().equals("ic2") && tokens.get(1).getValue().equals("-") && tokens.get(2).getValue().equals("item") && tokens.get(3).getValue().equals(":")) { + String name = tokens.get(4).getValue(); + int meta = 0; + if(tokens.size() > 6 && tokens.get(5).getValue().equals(":")) { + if(tokens.get(6).getType() == ZenTokener.T_INTVALUE) { + meta = Integer.parseInt(tokens.get(6).getValue()); + } else if(tokens.get(6).getValue().equals("*")) { + meta = OreDictionary.WILDCARD_VALUE; + } else { + MineTweakerAPI.logError("Not a valid meta value: " + tokens.get(6).getValue()); + } + } + ItemStack item = IC2Items.getItem(name); + if(item == null) { + MineTweakerAPI.logError("Not a valid IC2 item: " + name); + return null; + } else { + return new ItemReferenceSymbol(environment, name, meta); + } + } else { + return null; + } + } else { + return null; + } + } + + // ############################# + // ### Private inner classes ### + // ############################# + + private class ItemReferenceSymbol implements IZenSymbol { + + private final IEnvironmentGlobal environment; + private final String name; + private final int meta; + + public ItemReferenceSymbol(IEnvironmentGlobal environment, String name, int meta) { + this.environment = environment; + this.name = name; + this.meta = meta; + } + + @Override + public IPartialExpression instance(ZenPosition position) { + return new ExpressionCallStatic(position, environment, method, new ExpressionString(position, name), new ExpressionInt(position, meta, ZenType.INT)); + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2ExplosionWhitelist.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2ExplosionWhitelist.java index ed5c0a8..7ba4222 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2ExplosionWhitelist.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2ExplosionWhitelist.java @@ -1,161 +1,164 @@ package minetweaker.mods.ic2; import ic2.api.tile.ExplosionWhitelist; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; +import minetweaker.*; import minetweaker.annotations.ModOnly; import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; import net.minecraft.block.Block; import net.minecraft.item.ItemStack; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** * Manages the explosion whitelist in IC2. Blocks on this whitelist will not resist * an explosion but won't be destroyed. - * + *

* The explosion code by default ignores blocks which absorb more than 1000 explosion power to * prevent abusing personal safes, Trade-O-Mats and other blocks to serve as a cheap and * invulnerable reactor chambers. Said blocks will not shield the explosion and won't get * destroyed. - * + * * @author Stan Hebben */ @ZenClass("mods.ic2.ExplosionWhitelist") @ModOnly("IC2") public class IC2ExplosionWhitelist { - /** - * Adds a block to the explosion whitelist. - * - * @param item item to add - */ - @ZenMethod - public static void add(IItemStack item) { - ItemStack iStack = getItemStack(item); - Block block = Block.getBlockFromItem(iStack.getItem()); - if (block == null) { - MineTweakerAPI.logError("This item is not a block"); - } else { - MineTweakerAPI.apply(new AddAction(block)); - } - } - - /** - * Removes a block from the explosion whitelist. - * - * @param item item to remove - */ - @ZenMethod - public static void remove(IItemStack item) { - ItemStack iStack = getItemStack(item); - Block block = Block.getBlockFromItem(iStack.getItem()); - if (block == null) { - MineTweakerAPI.logError("This item is not a block"); - } else { - if (ExplosionWhitelist.isBlockWhitelisted(block)) { - MineTweakerAPI.logWarning("This block is not in the whitelist"); - } else { - MineTweakerAPI.apply(new RemoveAction(block)); - } - } - } - - /** - * Checks if the given item is already whitelisted. - * - * @param item item to check - * @return true if whitelisted - */ - @ZenMethod - public static boolean isWhitelisted(IItemStack item) { - ItemStack iStack = getItemStack(item); - Block block = Block.getBlockFromItem(iStack.getItem()); - if (block == null) { - MineTweakerAPI.logWarning("This item is not a block"); - return false; - } else { - return ExplosionWhitelist.isBlockWhitelisted(block); - } - } - - // ###################### - // ### Action classes ### - // ###################### - - private static class AddAction implements IUndoableAction { - private final Block block; - - public AddAction(Block block) { - this.block = block; - } - - @Override - public void apply() { - ExplosionWhitelist.addWhitelistedBlock(block); - } - @Override - public boolean canUndo() { - return true; - } + /** + * Adds a block to the explosion whitelist. + * + * @param item item to add + */ + @ZenMethod + public static void add(IItemStack item) { + ItemStack iStack = getItemStack(item); + Block block = Block.getBlockFromItem(iStack.getItem()); + if(block == null) { + MineTweakerAPI.logError("This item is not a block"); + } else { + MineTweakerAPI.apply(new AddAction(block)); + } + } - @Override - public void undo() { - ExplosionWhitelist.removeWhitelistedBlock(block); - } + /** + * Removes a block from the explosion whitelist. + * + * @param item item to remove + */ + @ZenMethod + public static void remove(IItemStack item) { + ItemStack iStack = getItemStack(item); + Block block = Block.getBlockFromItem(iStack.getItem()); + if(block == null) { + MineTweakerAPI.logError("This item is not a block"); + } else { + if(ExplosionWhitelist.isBlockWhitelisted(block)) { + MineTweakerAPI.logWarning("This block is not in the whitelist"); + } else { + MineTweakerAPI.apply(new RemoveAction(block)); + } + } + } - @Override - public String describe() { - return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName(); - } + /** + * Checks if the given item is already whitelisted. + * + * @param item item to check + * + * @return true if whitelisted + */ + @ZenMethod + public static boolean isWhitelisted(IItemStack item) { + ItemStack iStack = getItemStack(item); + Block block = Block.getBlockFromItem(iStack.getItem()); + if(block == null) { + MineTweakerAPI.logWarning("This item is not a block"); + return false; + } else { + return ExplosionWhitelist.isBlockWhitelisted(block); + } + } - @Override - public String describeUndo() { - return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName(); - } + // ###################### + // ### Action classes ### + // ###################### - @Override - public Object getOverrideKey() { - return null; - } - } - - private static class RemoveAction implements IUndoableAction { - private final Block block; - - public RemoveAction(Block block) { - this.block = block; - } - - @Override - public void apply() { - ExplosionWhitelist.removeWhitelistedBlock(block); - } + private static class AddAction implements IUndoableAction { - @Override - public boolean canUndo() { - return true; - } + private final Block block; - @Override - public void undo() { - ExplosionWhitelist.addWhitelistedBlock(block); - } + public AddAction(Block block) { + this.block = block; + } - @Override - public String describe() { - return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName(); - } + @Override + public void apply() { + ExplosionWhitelist.addWhitelistedBlock(block); + } - @Override - public String describeUndo() { - return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName(); - } + @Override + public boolean canUndo() { + return true; + } - @Override - public Object getOverrideKey() { - return null; - } - } + @Override + public void undo() { + ExplosionWhitelist.removeWhitelistedBlock(block); + } + + @Override + public String describe() { + return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName(); + } + + @Override + public String describeUndo() { + return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + } + + private static class RemoveAction implements IUndoableAction { + + private final Block block; + + public RemoveAction(Block block) { + this.block = block; + } + + @Override + public void apply() { + ExplosionWhitelist.removeWhitelistedBlock(block); + } + + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + ExplosionWhitelist.addWhitelistedBlock(block); + } + + @Override + public String describe() { + return "Removing block from IC2 explosion whitelist: " + block.getLocalizedName(); + } + + @Override + public String describeUndo() { + return "Adding block to IC2 explosion whitelist: " + block.getLocalizedName(); + } + + @Override + public Object getOverrideKey() { + return null; + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2RecipeInput.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2RecipeInput.java index 315d0d6..815412e 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2RecipeInput.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/IC2RecipeInput.java @@ -1,70 +1,59 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2; import ic2.api.recipe.IRecipeInput; -import java.util.ArrayList; -import java.util.List; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; +import minetweaker.api.minecraft.MineTweakerMC; import net.minecraft.item.ItemStack; +import java.util.List; +import java.util.stream.Collectors; + +import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; + /** * Wrapper class for ITweakerItemStackPatterns to IC2 recipe inputs. - * + * * @author Stan Hebben */ public class IC2RecipeInput implements IRecipeInput { - private final IIngredient ingredient; - - public IC2RecipeInput(IIngredient ingredient) { - this.ingredient = ingredient; - } - @Override - public boolean matches(ItemStack subject) { - return ingredient.matches(getIItemStack(subject)); - } + private final IIngredient ingredient; - @Override - public int getAmount() { - return ingredient.getAmount(); - } + public IC2RecipeInput(IIngredient ingredient) { + this.ingredient = ingredient; + } - @Override - public List getInputs() { - List items = new ArrayList(); - for (IItemStack item : ingredient.getItems()) { - items.add(getItemStack(item)); - } - return items; - } + @Override + public boolean matches(ItemStack subject) { + return ingredient.matches(getIItemStack(subject)); + } - @Override - public int hashCode() { - int hash = 7; - hash = 89 * hash + (this.ingredient != null ? this.ingredient.hashCode() : 0); - return hash; - } + @Override + public int getAmount() { + return ingredient.getAmount(); + } - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final IC2RecipeInput other = (IC2RecipeInput) obj; - if (this.ingredient != other.ingredient && (this.ingredient == null || !this.ingredient.equals(other.ingredient))) { - return false; - } - return true; - } + @Override + public List getInputs() { + return ingredient.getItems().stream().map(MineTweakerMC::getItemStack).collect(Collectors.toList()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 89 * hash + (this.ingredient != null ? this.ingredient.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final IC2RecipeInput other = (IC2RecipeInput) obj; + return !(this.ingredient != other.ingredient && (this.ingredient == null || !this.ingredient.equals(other.ingredient))); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/MachineAddRecipeAction.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/MachineAddRecipeAction.java index 263f40d..ee6299c 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/MachineAddRecipeAction.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/MachineAddRecipeAction.java @@ -1,8 +1,7 @@ package minetweaker.mods.ic2; import ic2.api.recipe.IMachineRecipeManager; -import minetweaker.MineTweakerAPI; -import minetweaker.OneWayAction; +import minetweaker.*; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -12,6 +11,7 @@ import java.util.Arrays; * @author Stan Hebben */ public class MachineAddRecipeAction extends OneWayAction { + private final String name; private final IMachineRecipeManager machine; private final ItemStack[] output; @@ -30,21 +30,21 @@ public class MachineAddRecipeAction extends OneWayAction { public void apply() { try { machine.addRecipe(input, tag, false, output); - } catch (RuntimeException ex) { + } catch(RuntimeException ex) { MineTweakerAPI.logError(ex.getMessage()); } } @Override public String describe() { - if (output.length == 1) { + if(output.length == 1) { return "Adding " + name + " recipe for " + output[0].getDisplayName(); } else { StringBuilder result = new StringBuilder(); result.append("Adding ").append(name).append(" recipe for "); result.append("["); - for (int i = 0; i < output.length; i++) { - if (i == 0) { + for(int i = 0; i < output.length; i++) { + if(i == 0) { result.append(", "); } else { result.append(output[i].getDisplayName()); @@ -73,28 +73,13 @@ public class MachineAddRecipeAction extends OneWayAction { @Override public boolean equals(Object obj) { - if (obj == null) { + if(obj == null) { return false; } - if (getClass() != obj.getClass()) { + if(getClass() != obj.getClass()) { return false; } final MachineAddRecipeAction other = (MachineAddRecipeAction) obj; - if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { - return false; - } - if (this.machine != other.machine && (this.machine == null || !this.machine.equals(other.machine))) { - return false; - } - if (!Arrays.deepEquals(this.output, other.output)) { - return false; - } - if (this.input != other.input && (this.input == null || !this.input.equals(other.input))) { - return false; - } - if (this.tag != other.tag && (this.tag == null || !this.tag.equals(other.tag))) { - return false; - } - return true; + return (this.name == null) ? other.name == null : this.name.equals(other.name) && !(this.machine != other.machine && (this.machine == null || !this.machine.equals(other.machine))) && Arrays.deepEquals(this.output, other.output) && !(this.input != other.input && (this.input == null || !this.input.equals(other.input))) && !(this.tag != other.tag && (this.tag == null || !this.tag.equals(other.tag))); } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/Crop.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/Crop.java index 0d699e9..32ced6e 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/Crop.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/Crop.java @@ -1,80 +1,77 @@ package minetweaker.mods.ic2.crops; import ic2.api.crops.CropCard; -import stanhebben.zenscript.annotations.ZenCaster; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; /** * Read-only data accessor for crops - * @author ben * + * @author ben */ @ZenClass("mods.ic2.Crop") public class Crop { - private CropCard cc; - @ZenGetter("name") - public String name() { - return cc.getName(); - } + private CropCard cc; - @ZenGetter("owner") - public String owner() { - return cc.getOwner(); - } + public Crop(CropCard cc) { + super(); + this.cc = cc; + } - @ZenGetter("displayName") - public String displayName() { - return cc.getDisplayName(); - } + @ZenGetter("name") + public String name() { + return cc.getName(); + } - @ZenGetter("hashCode") - public int hashCode() { - return cc.hashCode(); - } + @ZenGetter("owner") + public String owner() { + return cc.getOwner(); + } - @ZenGetter("discoveredBy") - public String discoveredBy() { - return cc.getDiscoveredBy(); - } + @ZenGetter("displayName") + public String displayName() { + return cc.getDisplayName(); + } - @ZenMethod - public String desc(int i) { - return cc.desc(i); - } + @ZenGetter("hashCode") + public int hashCode() { + return cc.hashCode(); + } - @ZenGetter("tier") - public int tier() { - return cc.getProperties().getTier(); - } + @ZenGetter("discoveredBy") + public String discoveredBy() { + return cc.getDiscoveredBy(); + } + @ZenMethod + public String desc(int i) { + return cc.desc(i); + } - @ZenGetter("attributes") - public String[] attributes() { - return cc.getAttributes(); - } + @ZenGetter("tier") + public int tier() { + return cc.getProperties().getTier(); + } - @ZenGetter("maxSize") - public int maxSize() { - return cc.getMaxSize(); - } + @ZenGetter("attributes") + public String[] attributes() { + return cc.getAttributes(); + } - @ZenGetter("dropGainChance") - public double dropGainChance() { - return cc.dropGainChance(); - } + @ZenGetter("maxSize") + public int maxSize() { + return cc.getMaxSize(); + } - @ZenCaster - public String toString() { - return cc.toString(); - } + @ZenGetter("dropGainChance") + public double dropGainChance() { + return cc.dropGainChance(); + } - public Crop(CropCard cc) { - super(); - this.cc = cc; - } + @ZenCaster + public String toString() { + return cc.toString(); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/CropsConfig.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/CropsConfig.java index 6fd6c3b..5b630ad 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/CropsConfig.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/CropsConfig.java @@ -1,20 +1,15 @@ package minetweaker.mods.ic2.crops; -import ic2.api.crops.CropCard; -import ic2.api.crops.Crops; -import minetweaker.MineTweakerAPI; -import minetweaker.OneWayAction; +import ic2.api.crops.*; +import minetweaker.*; import minetweaker.annotations.ModOnly; import minetweaker.api.item.IItemStack; import minetweaker.api.minecraft.MineTweakerMC; import net.minecraftforge.common.BiomeDictionary; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * Provides access to IC2 crop system in general @@ -24,238 +19,237 @@ import java.util.List; @ZenClass("mods.ic2.CropsConfig") @ModOnly("IC2") public class CropsConfig { - /** - * Action to add a new seed for a base crop - * @author ben - * - */ - private static final class RegisterBaseSeedAction extends OneWayAction { - private IItemStack seed; - private CropCard c; - private int sz; - private int growth; - private int gain; - private int resist; - public RegisterBaseSeedAction(IItemStack seed, CropCard c, int sz, int growth, int gain, int resist) { - this.seed = seed; - this.c = c; - this.sz = sz; - this.growth = growth; - this.gain = gain; - this.resist = resist; - } + /** + * Add a nutrient bonus to crops in a specific biome + */ + @ZenMethod + public static void addBiomeNutrientBonus(String biomeType, int nutrientBonus) { + if(BiomeDictionary.Type.valueOf(biomeType) == null) { + MineTweakerAPI.logWarning("invalid biome type: " + biomeType); + } else if(nutrientBonus < -10 || nutrientBonus > 10) { + MineTweakerAPI.logWarning("nutrient bonus " + nutrientBonus + " not in -10, +10 range"); + } else { + MineTweakerAPI.apply(new AddBiomeNutrientBonusAction(biomeType, nutrientBonus)); + } + } - @Override - public Object getOverrideKey() { - return null; - } + /** + * Add a humidity bonus to crops in a specific biome + */ + @ZenMethod + public static void addBiomeHumidityBonus(String biomeType, int humidityBonus) { + if(BiomeDictionary.Type.valueOf(biomeType) == null) { + MineTweakerAPI.logWarning("invalid biome type: " + biomeType); + } else if(humidityBonus < -10 || humidityBonus > 10) { + MineTweakerAPI.logWarning("humidity bonus " + humidityBonus + " not in -10, +10 range"); + } else { + MineTweakerAPI.apply(new AddBiomeHumidityBonusAction(biomeType, humidityBonus)); + } + } - @Override - public String describe() { - return "Registering base seed for crop " + c.getName(); - } + /** + * Creates a new synthetic crop to manipulate + * + * @param cropOwner The mod that owns the crop + * @param cropName The name of the crop + */ + @ZenMethod + public static SyntheticCrop newCrop(String cropName, String cropOwner) { + return new SyntheticCrop(cropName, cropOwner); + } - @Override - public void apply() { - Crops.instance.registerBaseSeed(MineTweakerMC.getItemStack(seed), c, sz, growth, gain, resist); - } - } - + /** + * Register a crop into the crop system + */ + @ZenMethod + public static void registerCrop(CropCard c) { + MineTweakerAPI.apply(new RegisterCropCardAction(c)); + } + /** + * Register a new base seed item to plant a crop + * + * @param seed The item to plant with + * @param c The crop being planted + * @param sz The initial size of the planted crop + * @param growth The initial growth stat of the planted crop + * @param gain The initial gain stat of the planted crop + * @param resist The initial resistance of the planted crop + */ + public static void registerBaseSeed(IItemStack seed, CropCard c, int sz, int growth, int gain, int resist) { + MineTweakerAPI.apply(new RegisterBaseSeedAction(seed, c, sz, growth, gain, resist)); + } - /** - * Action to register a new crop - * @author ben - * - */ - private static final class RegisterCropCardAction extends OneWayAction { - private CropCard c; + /** + * Get a crop by its name and owning mod + * + * @param owner The mod that owns the crop + * @param name The name of the crop + * + * @return A crop with the given name, owned by the given mod + */ + @ZenMethod + public static Crop getCrop(String owner, String name) { + return new Crop(Crops.instance.getCropCard(owner, name)); + } - public RegisterCropCardAction(CropCard c) { - this.c = c; - } + /** + * Get a crop by the seed that plants it + * + * @param seed The seed that plants the crop + * + * @return The crop planted by the seed + */ + @ZenMethod + public static Crop getCrop(IItemStack seed) { + return new Crop(Crops.instance.getCropCard(MineTweakerMC.getItemStack(seed))); + } - @Override - public Object getOverrideKey() { - return null; - } + /** + * Get all of the currently registered crops + * + * @return All of the currently registered crops + */ + @ZenGetter("crops") + public static List getAllCrops() { + Collection ccList = Crops.instance.getCrops(); - @Override - public String describe() { - return "Registering crop " + c.getName(); - } + List cList = new ArrayList<>(ccList.size()); + cList.addAll(ccList.stream().map(Crop::new).collect(Collectors.toList())); - @Override - public void apply() { - Crops.instance.registerCrop(c); - } - } - + return cList; + } - /** - * Action to add a biome nutrient bonus - * @author ben - * - */ - private static final class AddBiomeNutrientBonusAction extends OneWayAction { - private String biomeType; - private int nutrientBonus; + /** + * Action to add a new seed for a base crop + * + * @author ben + */ + private static final class RegisterBaseSeedAction extends OneWayAction { - public AddBiomeNutrientBonusAction(String biomeType, int nutrientBonus) { - this.biomeType = biomeType; - this.nutrientBonus = nutrientBonus; - } + private IItemStack seed; + private CropCard c; + private int sz; + private int growth; + private int gain; + private int resist; - @Override - public Object getOverrideKey() { - // TODO Auto-generated method stub - return null; - } + public RegisterBaseSeedAction(IItemStack seed, CropCard c, int sz, int growth, int gain, int resist) { + this.seed = seed; + this.c = c; + this.sz = sz; + this.growth = growth; + this.gain = gain; + this.resist = resist; + } - @Override - public String describe() { - return "Setting biome nutrient bonus for " + biomeType + " biomes to " + - nutrientBonus; - } + @Override + public Object getOverrideKey() { + return null; + } - @Override - public void apply() { - Crops.instance.addBiomenutrientsBonus(BiomeDictionary.Type.valueOf(biomeType), - nutrientBonus); - } - } - - /** - * Action to add a biome humidity bonus - * @author ben - * - */ - private static final class AddBiomeHumidityBonusAction extends OneWayAction { - private String biomeType; - private int humidityBonus; + @Override + public String describe() { + return "Registering base seed for crop " + c.getName(); + } - public AddBiomeHumidityBonusAction(String biomeType, int humidityBonus) { - this.biomeType = biomeType; - this.humidityBonus = humidityBonus; - } + @Override + public void apply() { + Crops.instance.registerBaseSeed(MineTweakerMC.getItemStack(seed), c, sz, growth, gain, resist); + } + } - @Override - public Object getOverrideKey() { - // TODO Auto-generated method stub - return null; - } + /** + * Action to register a new crop + * + * @author ben + */ + private static final class RegisterCropCardAction extends OneWayAction { - @Override - public String describe() { - return "Setting biome humidity bonus for " + biomeType + " biomes to " + - humidityBonus; - } + private CropCard c; - @Override - public void apply() { - Crops.instance.addBiomehumidityBonus(BiomeDictionary.Type.valueOf(biomeType), - humidityBonus); - } - } - - /** - * Add a nutrient bonus to crops in a specific biome - */ - @ZenMethod - public static void addBiomeNutrientBonus(String biomeType, int nutrientBonus) { - if(BiomeDictionary.Type.valueOf(biomeType) == null) { - MineTweakerAPI.logWarning("invalid biome type: " + biomeType); - } else if (nutrientBonus < -10 || nutrientBonus > 10) { - MineTweakerAPI.logWarning("nutrient bonus " + nutrientBonus + - " not in -10, +10 range"); - } else { - MineTweakerAPI.apply(new AddBiomeNutrientBonusAction(biomeType, nutrientBonus)); - } - } - - /** - * Add a humidity bonus to crops in a specific biome - */ - @ZenMethod - public static void addBiomeHumidityBonus(String biomeType, int humidityBonus) { - if(BiomeDictionary.Type.valueOf(biomeType) == null) { - MineTweakerAPI.logWarning("invalid biome type: " + biomeType); - } else if (humidityBonus < -10 || humidityBonus > 10) { - MineTweakerAPI.logWarning("humidity bonus " + humidityBonus + - " not in -10, +10 range"); - } else { - MineTweakerAPI.apply(new AddBiomeHumidityBonusAction(biomeType, humidityBonus)); - } - } + public RegisterCropCardAction(CropCard c) { + this.c = c; + } - /** - * Creates a new synthetic crop to manipulate - * @param cropOwner The mod that owns the crop - * @param cropName The name of the crop - */ - @ZenMethod - public static SyntheticCrop newCrop(String cropName, String cropOwner) { - return new SyntheticCrop(cropName, cropOwner); - } - - /** - * Register a crop into the crop system - */ - @ZenMethod - public static void registerCrop(CropCard c) { - MineTweakerAPI.apply(new RegisterCropCardAction(c)); - } - - /** - * Register a new base seed item to plant a crop - * - * @param seed The item to plant with - * @param c The crop being planted - * @param sz The initial size of the planted crop - * @param growth The initial growth stat of the planted crop - * @param gain The initial gain stat of the planted crop - * @param resist The initial resistance of the planted crop - */ - public static void registerBaseSeed(IItemStack seed, CropCard c, int sz, - int growth, int gain, int resist) { - MineTweakerAPI.apply(new RegisterBaseSeedAction(seed, c, sz, growth, gain, resist)); - } + @Override + public Object getOverrideKey() { + return null; + } - /** - * Get a crop by its name and owning mod - * @param owner The mod that owns the crop - * @param name The name of the crop - * @return A crop with the given name, owned by the given mod - */ - @ZenMethod - public static Crop getCrop(String owner, String name) { - return new Crop(Crops.instance.getCropCard(owner, name)); - } - - /** - * Get a crop by the seed that plants it - * @param seed The seed that plants the crop - * @return The crop planted by the seed - */ - @ZenMethod - public static Crop getCrop(IItemStack seed) { - return new Crop(Crops.instance.getCropCard(MineTweakerMC.getItemStack(seed))); - } + @Override + public String describe() { + return "Registering crop " + c.getName(); + } - /** - * Get all of the currently registered crops - * @return All of the currently registered crops - */ - @ZenGetter("crops") - public static List getAllCrops() { - Collection ccList = Crops.instance.getCrops(); - - List cList = new ArrayList(ccList.size()); - for (CropCard cropCard : ccList) { - cList.add(new Crop(cropCard)); - } - - return cList; - } + @Override + public void apply() { + Crops.instance.registerCrop(c); + } + } + + /** + * Action to add a biome nutrient bonus + * + * @author ben + */ + private static final class AddBiomeNutrientBonusAction extends OneWayAction { + + private String biomeType; + private int nutrientBonus; + + public AddBiomeNutrientBonusAction(String biomeType, int nutrientBonus) { + this.biomeType = biomeType; + this.nutrientBonus = nutrientBonus; + } + + @Override + public Object getOverrideKey() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String describe() { + return "Setting biome nutrient bonus for " + biomeType + " biomes to " + nutrientBonus; + } + + @Override + public void apply() { + Crops.instance.addBiomenutrientsBonus(BiomeDictionary.Type.valueOf(biomeType), nutrientBonus); + } + } + + /** + * Action to add a biome humidity bonus + * + * @author ben + */ + private static final class AddBiomeHumidityBonusAction extends OneWayAction { + + private String biomeType; + private int humidityBonus; + + public AddBiomeHumidityBonusAction(String biomeType, int humidityBonus) { + this.biomeType = biomeType; + this.humidityBonus = humidityBonus; + } + + @Override + public Object getOverrideKey() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String describe() { + return "Setting biome humidity bonus for " + biomeType + " biomes to " + humidityBonus; + } + + @Override + public void apply() { + Crops.instance.addBiomehumidityBonus(BiomeDictionary.Type.valueOf(biomeType), humidityBonus); + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/GrowthRequirements.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/GrowthRequirements.java index c7d9ea1..69166a2 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/GrowthRequirements.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/GrowthRequirements.java @@ -1,144 +1,152 @@ package minetweaker.mods.ic2.crops; import minetweaker.api.item.IItemStack; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenSetter; +import stanhebben.zenscript.annotations.*; /** * Contains all of the growth requirements for an IC2 crop in one easy place - * @author ben * + * @author ben */ @ZenClass("mods.ic2.GrowthRequirements") public class GrowthRequirements { - - private int minNutrients; - private int minHumidity; - private int minAirQuality; - - private int minLight; - private int maxLight = 17; - - private IItemStack requiredBlock; - /** - * Get the minimum amount of nutrients this plant needs to grow - * @return The minimum amount of nutrients this plant needs - */ - @ZenGetter("minNutrients") - public int getMinNutrients() { - return minNutrients; - } + private int minNutrients; + private int minHumidity; + private int minAirQuality; - /** - * Set the minimum amount of nutrients this plant needs to grow - * @param minNutrients The new minimum amount of nutrients this plant requires - */ - @ZenSetter("minNutrients") - public void setMinNutrients(int minNutrients) { - this.minNutrients = minNutrients; - } + private int minLight; + private int maxLight = 17; - /** - * Get the minimum amount of humidity this plant requires - * @return The minimum amount of humidity this plant requires - */ - @ZenGetter("minHumidity") - public int getMinHumidity() { - return minHumidity; - } + private IItemStack requiredBlock; - /** - * Set the minimum amount of humidity this plant requires - * @param minHumidity The new minimum amount of humidity this plant requires - */ - @ZenSetter("minHumidity") - public void setMinHumidity(int minHumidity) { - this.minHumidity = minHumidity; - } + public GrowthRequirements(int minNutrients, int minHumidity, int minAirQuality, int minLight, int maxLight, IItemStack requiredBlock) { + super(); + this.minNutrients = minNutrients; + this.minHumidity = minHumidity; + this.minAirQuality = minAirQuality; + this.minLight = minLight; + this.maxLight = maxLight; + this.requiredBlock = requiredBlock; + } - /** - * Get the minimum air quality this plant requires - * @return The minimum air quality this plant requires - */ - @ZenGetter("minAirQuality") - public int getMinAirQuality() { - return minAirQuality; - } + /** + * Get the minimum amount of nutrients this plant needs to grow + * + * @return The minimum amount of nutrients this plant needs + */ + @ZenGetter("minNutrients") + public int getMinNutrients() { + return minNutrients; + } - /** - * Set the minimum air quality this plant requires - * @param minAirQuality The new amount of air quality this plant requires - */ - @ZenSetter("minAirQuality") - public void setMinAirQuality(int minAirQuality) { - this.minAirQuality = minAirQuality; - } + /** + * Set the minimum amount of nutrients this plant needs to grow + * + * @param minNutrients The new minimum amount of nutrients this plant requires + */ + @ZenSetter("minNutrients") + public void setMinNutrients(int minNutrients) { + this.minNutrients = minNutrients; + } - /** - * Get the minimum amount of light this plant requires - * @return The minimum amount of light this plant requires - */ - @ZenGetter("minLight") - public int getMinLight() { - return minLight; - } + /** + * Get the minimum amount of humidity this plant requires + * + * @return The minimum amount of humidity this plant requires + */ + @ZenGetter("minHumidity") + public int getMinHumidity() { + return minHumidity; + } - /** - * Set the minimum amount of light this plant requires - * @param minLight The new minimum amount of light this plant requires - */ - @ZenSetter("minLight") - public void setMinLight(int minLight) { - this.minLight = minLight; - } + /** + * Set the minimum amount of humidity this plant requires + * + * @param minHumidity The new minimum amount of humidity this plant requires + */ + @ZenSetter("minHumidity") + public void setMinHumidity(int minHumidity) { + this.minHumidity = minHumidity; + } - /** - * Get the maximum amount of light this plant can have - * @return The maximum amount of light this plant can have - */ - @ZenGetter("maxLight") - public int getMaxLight() { - return maxLight; - } + /** + * Get the minimum air quality this plant requires + * + * @return The minimum air quality this plant requires + */ + @ZenGetter("minAirQuality") + public int getMinAirQuality() { + return minAirQuality; + } - /** - * Set the maximum amount of light this plant can have - * @param maxLight The new maximum amount of light thi plant can have - */ - @ZenSetter("maxLight") - public void setMaxLight(int maxLight) { - this.maxLight = maxLight; - } + /** + * Set the minimum air quality this plant requires + * + * @param minAirQuality The new amount of air quality this plant requires + */ + @ZenSetter("minAirQuality") + public void setMinAirQuality(int minAirQuality) { + this.minAirQuality = minAirQuality; + } - /** - * Get the block that is required to be below this one - * @return The block required to be below this one - */ - @ZenGetter("requiredBlock") - public IItemStack getRequiredBlock() { - return requiredBlock; - } + /** + * Get the minimum amount of light this plant requires + * + * @return The minimum amount of light this plant requires + */ + @ZenGetter("minLight") + public int getMinLight() { + return minLight; + } - /** - * Set the block required to be below this one - * @param requiredBlock The new block required to be below this one - */ - @ZenSetter("requiredBlock") - public void setRequiredBlock(IItemStack requiredBlock) { - this.requiredBlock = requiredBlock; - } + /** + * Set the minimum amount of light this plant requires + * + * @param minLight The new minimum amount of light this plant requires + */ + @ZenSetter("minLight") + public void setMinLight(int minLight) { + this.minLight = minLight; + } - - public GrowthRequirements(int minNutrients, int minHumidity, int minAirQuality, int minLight, int maxLight, - IItemStack requiredBlock) { - super(); - this.minNutrients = minNutrients; - this.minHumidity = minHumidity; - this.minAirQuality = minAirQuality; - this.minLight = minLight; - this.maxLight = maxLight; - this.requiredBlock = requiredBlock; - } + /** + * Get the maximum amount of light this plant can have + * + * @return The maximum amount of light this plant can have + */ + @ZenGetter("maxLight") + public int getMaxLight() { + return maxLight; + } + + /** + * Set the maximum amount of light this plant can have + * + * @param maxLight The new maximum amount of light thi plant can have + */ + @ZenSetter("maxLight") + public void setMaxLight(int maxLight) { + this.maxLight = maxLight; + } + + /** + * Get the block that is required to be below this one + * + * @return The block required to be below this one + */ + @ZenGetter("requiredBlock") + public IItemStack getRequiredBlock() { + return requiredBlock; + } + + /** + * Set the block required to be below this one + * + * @param requiredBlock The new block required to be below this one + */ + @ZenSetter("requiredBlock") + public void setRequiredBlock(IItemStack requiredBlock) { + this.requiredBlock = requiredBlock; + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/SyntheticCrop.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/SyntheticCrop.java index a6d5563..de22596 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/SyntheticCrop.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/crops/SyntheticCrop.java @@ -1,16 +1,11 @@ package minetweaker.mods.ic2.crops; -import ic2.api.crops.CropCard; -import ic2.api.crops.CropProperties; -import ic2.api.crops.ICropTile; +import ic2.api.crops.*; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; import minetweaker.api.minecraft.MineTweakerMC; import net.minecraft.item.ItemStack; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenMethod; -import stanhebben.zenscript.annotations.ZenSetter; +import stanhebben.zenscript.annotations.*; /** * A synthetic crop, created in ZS @@ -80,6 +75,11 @@ public class SyntheticCrop extends CropCard { return properties; } + @ZenSetter("properties") + public void setProperties(CropProperties properties) { + this.properties = properties; + } + /** * Gets the localization key used for this crop */ @@ -96,7 +96,6 @@ public class SyntheticCrop extends CropCard { return tier; } - /** * Gets any additional attributes of this crop */ @@ -106,6 +105,16 @@ public class SyntheticCrop extends CropCard { return attributes; } + /** + * Sets the additional attributes for this crop + * + * @param attributes Sets the attributes of this crop + */ + @ZenSetter("attributes") + public void setAttributes(String[] attributes) { + this.attributes = attributes; + } + /** * Gets the maximum size of this crop */ @@ -115,21 +124,30 @@ public class SyntheticCrop extends CropCard { return maxSize; } + /** + * Sets the maximum size this crop goes to + * + * @param maxSize The new max size of this crop + */ + @ZenSetter("maxSize") + public void setMaxSize(int maxSize) { + this.maxSize = maxSize; + } @Override public boolean canGrow(ICropTile crop) { - if (crop.getCurrentSize() == maxSize) { + if(crop.getCurrentSize() == maxSize) { return false; - } else if (reqs == null) { + } else if(reqs == null) { return true; } else { - if (!crop.isBlockBelow(MineTweakerMC.getBlock(reqs.getRequiredBlock()))) { + if(!crop.isBlockBelow(MineTweakerMC.getBlock(reqs.getRequiredBlock()))) { return false; - } else if (crop.getAirQuality() < reqs.getMinAirQuality()) { + } else if(crop.getAirQuality() < reqs.getMinAirQuality()) { return false; - } else if (crop.getHumidity() < reqs.getMinHumidity()) { + } else if(crop.getHumidity() < reqs.getMinHumidity()) { return false; - } else if (crop.getNutrients() < reqs.getMinNutrients()) { + } else if(crop.getNutrients() < reqs.getMinNutrients()) { return false; } else { int lgh = crop.getLightLevel(); @@ -138,6 +156,7 @@ public class SyntheticCrop extends CropCard { } } + // ZS Support @Override public boolean canBeHarvested(ICropTile crop) { @@ -158,8 +177,6 @@ public class SyntheticCrop extends CropCard { return dropChance; } -// ZS Support - /** * Sets the tier of this crop * @@ -188,33 +205,13 @@ public class SyntheticCrop extends CropCard { */ @ZenMethod public void setStat(int stat, int val) { - if (stat < 0 || stat > 3) { + if(stat < 0 || stat > 3) { MineTweakerAPI.logWarning("invalid stat index " + stat); } else { stats[stat] = val; } } - /** - * Sets the additional attributes for this crop - * - * @param attributes Sets the attributes of this crop - */ - @ZenSetter("attributes") - public void setAttributes(String[] attributes) { - this.attributes = attributes; - } - - /** - * Sets the maximum size this crop goes to - * - * @param maxSize The new max size of this crop - */ - @ZenSetter("maxSize") - public void setMaxSize(int maxSize) { - this.maxSize = maxSize; - } - /** * Sets the item this crop gives when harvested * @@ -252,10 +249,4 @@ public class SyntheticCrop extends CropCard { public void setReqs(GrowthRequirements reqs) { this.reqs = reqs; } - - - @ZenSetter("properties") - public void setProperties(CropProperties properties) { - this.properties = properties; - } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/IngredientExpansion.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/IngredientExpansion.java index 864766a..6e36e93 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/IngredientExpansion.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/IngredientExpansion.java @@ -1,54 +1,28 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.expand; import minetweaker.annotations.ModOnly; import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemCondition; -import minetweaker.api.item.IItemStack; -import minetweaker.api.item.IItemTransformer; -import minetweaker.api.player.IPlayer; -import stanhebben.zenscript.annotations.ZenExpansion; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; /** - * * @author Stan */ @ZenExpansion("minetweaker.item.IIngredient") @ModOnly("IC2") public class IngredientExpansion { - @ZenMethod - public static IIngredient onlyIC2ChargeAtLeast(IIngredient ingredient, final int charge) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return ItemExpansion.getIC2Charge(stack) >= charge; - } - }); - } - - @ZenMethod - public static IIngredient onlyIC2ChargeAtMost(IIngredient ingredient, final int charge) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return ItemExpansion.getIC2Charge(stack) <= charge; - } - }); - } - - @ZenMethod - public static IIngredient transformIC2Discharge(IIngredient ingredient, final int amount) { - return ingredient.transform(new IItemTransformer() { - @Override - public IItemStack transform(IItemStack item, IPlayer byPlayer) { - return ItemExpansion.ic2Discharge(item, amount, 0).withAmount(item.getAmount() + 1); - } - }); - } + + @ZenMethod + public static IIngredient onlyIC2ChargeAtLeast(IIngredient ingredient, final int charge) { + return ingredient.only(stack -> ItemExpansion.getIC2Charge(stack) >= charge); + } + + @ZenMethod + public static IIngredient onlyIC2ChargeAtMost(IIngredient ingredient, final int charge) { + return ingredient.only(stack -> ItemExpansion.getIC2Charge(stack) <= charge); + } + + @ZenMethod + public static IIngredient transformIC2Discharge(IIngredient ingredient, final int amount) { + return ingredient.transform((item, byPlayer) -> ItemExpansion.ic2Discharge(item, amount, 0).withAmount(item.getAmount() + 1)); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/ItemExpansion.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/ItemExpansion.java index cee9c08..76e3f3a 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/ItemExpansion.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/expand/ItemExpansion.java @@ -1,104 +1,104 @@ package minetweaker.mods.ic2.expand; -import ic2.api.item.ElectricItem; -import ic2.api.item.IElectricItem; +import ic2.api.item.*; import minetweaker.annotations.ModOnly; import minetweaker.api.item.IItemStack; import net.minecraft.item.ItemStack; -import stanhebben.zenscript.annotations.Optional; -import stanhebben.zenscript.annotations.ZenExpansion; -import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; +import static minetweaker.api.minecraft.MineTweakerMC.*; /** - * * @author Stan */ @ZenExpansion("minecraft.item.IItemStack") @ModOnly("IC2") public class ItemExpansion { - /** - * Gets the charge level of this item. - * - * @param stack target - * @return charge level - */ - @ZenGetter("ic2getCharge") - public static double getIC2Charge(IItemStack stack) { - return ElectricItem.manager.getCharge(getItemStack(stack)); - } - - /** - * Gets the tier level of this item. - * - * @param stack target - * @return tier level - */ - @ZenGetter("ic2tier") - public static int getIC2Tier(IItemStack stack) { - ItemStack iStack = getItemStack(stack); - if (iStack.getItem() instanceof IElectricItem) { - return ((IElectricItem) iStack.getItem()).getTier(iStack); - } else { - return 0; - } - } - - /** - * Gets the transfer limit of the specified stack. - * - * @param stack target - * @return - */ - @ZenGetter("ic2transferLimit") - public static double getIC2TransferLimit(IItemStack stack) { - ItemStack iStack = getItemStack(stack); - if (iStack.getItem() instanceof IElectricItem) { - return ((IElectricItem) iStack.getItem()).getTransferLimit(iStack); - } else { - return 0; - } - } - - /** - * Charges the item with the specified amount and returns the charged item. - * - * @param stack target - * @param amount charge amount - * @param tier charge tier - * @return charged item - */ - @ZenMethod("ic2charge") - public static IItemStack ic2Charge(IItemStack stack, double amount, @Optional int tier) { - if (tier == 0) { - tier = getIC2Tier(stack); - } - - ItemStack iStack = getItemStack(stack).copy(); - ElectricItem.manager.charge(iStack, amount, tier, true, false); - return getIItemStack(iStack); - } - - /** - * Discharges the item with the specified amount and returns the discharged item. - * - * @param stack target - * @param amount discharge amount - * @param tier charge tier - * @return discharged item - */ - @ZenMethod("ic2discharge") - public static IItemStack ic2Discharge(IItemStack stack, int amount, @Optional int tier) { - if (tier == 0) { - tier = getIC2Tier(stack); - } - - ItemStack iStack = getItemStack(stack).copy(); - ElectricItem.manager.discharge(iStack, amount, tier, true, false, false); - return getIItemStack(iStack); - } + /** + * Gets the charge level of this item. + * + * @param stack target + * + * @return charge level + */ + @ZenGetter("ic2getCharge") + public static double getIC2Charge(IItemStack stack) { + return ElectricItem.manager.getCharge(getItemStack(stack)); + } + + /** + * Gets the tier level of this item. + * + * @param stack target + * + * @return tier level + */ + @ZenGetter("ic2tier") + public static int getIC2Tier(IItemStack stack) { + ItemStack iStack = getItemStack(stack); + if(iStack.getItem() instanceof IElectricItem) { + return ((IElectricItem) iStack.getItem()).getTier(iStack); + } else { + return 0; + } + } + + /** + * Gets the transfer limit of the specified stack. + * + * @param stack target + * + * @return + */ + @ZenGetter("ic2transferLimit") + public static double getIC2TransferLimit(IItemStack stack) { + ItemStack iStack = getItemStack(stack); + if(iStack.getItem() instanceof IElectricItem) { + return ((IElectricItem) iStack.getItem()).getTransferLimit(iStack); + } else { + return 0; + } + } + + + /** + * Charges the item with the specified amount and returns the charged item. + * + * @param stack target + * @param amount charge amount + * @param tier charge tier + * + * @return charged item + */ + @ZenMethod("ic2charge") + public static IItemStack ic2Charge(IItemStack stack, double amount, @Optional int tier) { + if(tier == 0) { + tier = getIC2Tier(stack); + } + + ItemStack iStack = getItemStack(stack).copy(); + ElectricItem.manager.charge(iStack, amount, tier, true, false); + return getIItemStack(iStack); + } + + /** + * Discharges the item with the specified amount and returns the discharged item. + * + * @param stack target + * @param amount discharge amount + * @param tier charge tier + * + * @return discharged item + */ + @ZenMethod("ic2discharge") + public static IItemStack ic2Discharge(IItemStack stack, int amount, @Optional int tier) { + if(tier == 0) { + tier = getIC2Tier(stack); + } + + ItemStack iStack = getItemStack(stack).copy(); + ElectricItem.manager.discharge(iStack, amount, tier, true, false, false); + return getIItemStack(iStack); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlastFurnace.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlastFurnace.java index 1631698..0aa63ea 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlastFurnace.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlastFurnace.java @@ -1,70 +1,54 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; -import stanhebben.zenscript.annotations.NotNull; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; +import stanhebben.zenscript.annotations.*; import static minetweaker.api.minecraft.MineTweakerMC.*; /** * Provides access to the IC2 Blast Furnace recipes. - * + * * @author Stan Hebben */ @ZenClass("mods.ic2.BlastFurnace") @ModOnly("IC2") public class BlastFurnace { - /** - * Adds a new recipe to the blast furnace. - * - * The recipe input can be any pattern, as long as the stack size is determined. - * The output can be any item stack. - * - * @param output recipe output - * @param ingredient recipe input - */ - @ZenMethod - public static void addRecipe( - @NotNull IItemStack output, - @NotNull IIngredient ingredient) { - if (ingredient.getAmount() < 0) { - MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); - } else { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "blast furnace", - Recipes.blastfurnace, - getItemStacks(output), - null, - new IC2RecipeInput(ingredient))); - } - } - - /** - * Determines the recipe output for the given input. Will return the output - * of a single item, even if the stack contains multiple items. - * - * @param input recipe input - * @return recipe output - */ - @ZenMethod - public static IItemStack getOutput( - @NotNull IItemStack input) { - RecipeOutput output = Recipes.blastfurnace.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStack(output.items.get(0)); - } + + /** + * Adds a new recipe to the blast furnace. + *

+ * The recipe input can be any pattern, as long as the stack size is determined. + * The output can be any item stack. + * + * @param output recipe output + * @param ingredient recipe input + */ + @ZenMethod + public static void addRecipe(@NotNull IItemStack output, @NotNull IIngredient ingredient) { + if(ingredient.getAmount() < 0) { + MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); + } else { + MineTweakerAPI.apply(new MachineAddRecipeAction("blast furnace", Recipes.blastfurnace, getItemStacks(output), null, new IC2RecipeInput(ingredient))); + } + } + + /** + * Determines the recipe output for the given input. Will return the output + * of a single item, even if the stack contains multiple items. + * + * @param input recipe input + * + * @return recipe output + */ + @ZenMethod + public static IItemStack getOutput(@NotNull IItemStack input) { + RecipeOutput output = Recipes.blastfurnace.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStack(output.items.get(0)); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlockCutter.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlockCutter.java index 06231fd..cada51f 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlockCutter.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/BlockCutter.java @@ -1,71 +1,54 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; -import stanhebben.zenscript.annotations.NotNull; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.*; /** * Provides access to the IC2 Block Cutter recipes. - * + * * @author Stan Hebben */ @ZenClass("mods.ic2.BlockCutter") @ModOnly("IC2") public class BlockCutter { - /** - * Adds a new recipe to the block cutter. - * - * The recipe input can be any pattern, as long as the stack size is determined. - * The output can be any item stack. - * - * @param output recipe output - * @param ingredient recipe input - */ - @ZenMethod - public static void addRecipe( - @NotNull IItemStack output, - @NotNull IIngredient ingredient) { - if (ingredient.getAmount() < 0) { - MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); - } else { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "block cutter", - Recipes.blockcutter, - getItemStacks(output), - null, - new IC2RecipeInput(ingredient))); - } - } - - /** - * Determines the recipe output for the given input. Will return the output - * of a single item, even if the stack contains multiple items. - * - * @param input recipe input - * @return recipe output - */ - @ZenMethod - public static IItemStack getOutput( - @NotNull IItemStack input) { - RecipeOutput output = Recipes.blockcutter.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStack(output.items.get(0)); - } + + /** + * Adds a new recipe to the block cutter. + *

+ * The recipe input can be any pattern, as long as the stack size is determined. + * The output can be any item stack. + * + * @param output recipe output + * @param ingredient recipe input + */ + @ZenMethod + public static void addRecipe(@NotNull IItemStack output, @NotNull IIngredient ingredient) { + if(ingredient.getAmount() < 0) { + MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); + } else { + MineTweakerAPI.apply(new MachineAddRecipeAction("block cutter", Recipes.blockcutter, getItemStacks(output), null, new IC2RecipeInput(ingredient))); + } + } + + /** + * Determines the recipe output for the given input. Will return the output + * of a single item, even if the stack contains multiple items. + * + * @param input recipe input + * + * @return recipe output + */ + @ZenMethod + public static IItemStack getOutput(@NotNull IItemStack input) { + RecipeOutput output = Recipes.blockcutter.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStack(output.items.get(0)); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Canner.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Canner.java index 6c698be..c920e31 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Canner.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Canner.java @@ -1,259 +1,215 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeInputFluidContainer; -import ic2.api.recipe.Recipes; -import minetweaker.MineTweakerAPI; -import minetweaker.OneWayAction; +import ic2.api.recipe.*; +import minetweaker.*; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; +import minetweaker.api.item.*; import minetweaker.api.liquid.ILiquidStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; import minetweaker.mods.ic2.IC2RecipeInput; import net.minecraftforge.fluids.FluidStack; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** - * * @author Stan */ @ZenClass("mods.ic2.Canner") @ModOnly("IC2") public class Canner { - @ZenMethod - public static void addBottleRecipe(IItemStack output, IIngredient container, IIngredient fill) { - MineTweakerAPI.apply(new AddBottleIngredientAction(container, fill, output)); - } - - @ZenMethod - public static void addBottleRecipe(IItemStack output, IIngredient container, ILiquidStack liquid) { - MineTweakerAPI.apply(new AddBottleLiquidAction(container, liquid, output)); - } - - @ZenMethod - public static void addEnrichRecipe(ILiquidStack output, ILiquidStack input, IIngredient additive) { - MineTweakerAPI.apply(new AddEnrichIngredientAction(input, additive, output)); - } - - @ZenMethod - public static void addEnrichRecipe(ILiquidStack output, ILiquidStack input, ILiquidStack additive) { - MineTweakerAPI.apply(new AddEnrichLiquidAction(input, additive, output)); - } - - private static class AddBottleIngredientAction extends OneWayAction { - private final IIngredient container; - private final IIngredient fill; - private final IItemStack output; - - public AddBottleIngredientAction(IIngredient container, IIngredient fill, IItemStack output) { - this.container = container; - this.fill = fill; - this.output = output; - } - - @Override - public void apply() { - Recipes.cannerBottle.addRecipe( - new IC2RecipeInput(container), - new IC2RecipeInput(fill), - getItemStack(output)); - } - @Override - public String describe() { - return "Adding canner bottle recipe " + container + " + " + fill + " => " + output; - } + @ZenMethod + public static void addBottleRecipe(IItemStack output, IIngredient container, IIngredient fill) { + MineTweakerAPI.apply(new AddBottleIngredientAction(container, fill, output)); + } - @Override - public Object getOverrideKey() { - return null; - } + @ZenMethod + public static void addBottleRecipe(IItemStack output, IIngredient container, ILiquidStack liquid) { + MineTweakerAPI.apply(new AddBottleLiquidAction(container, liquid, output)); + } - @Override - public int hashCode() { - int hash = 7; - hash = 67 * hash + (this.container != null ? this.container.hashCode() : 0); - hash = 67 * hash + (this.fill != null ? this.fill.hashCode() : 0); - hash = 67 * hash + (this.output != null ? this.output.hashCode() : 0); - return hash; - } + @ZenMethod + public static void addEnrichRecipe(ILiquidStack output, ILiquidStack input, IIngredient additive) { + MineTweakerAPI.apply(new AddEnrichIngredientAction(input, additive, output)); + } - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AddBottleIngredientAction other = (AddBottleIngredientAction) obj; - if (this.container != other.container && (this.container == null || !this.container.equals(other.container))) { - return false; - } - if (this.fill != other.fill && (this.fill == null || !this.fill.equals(other.fill))) { - return false; - } - if (this.output != other.output && (this.output == null || !this.output.equals(other.output))) { - return false; - } - return true; - } - } - - private static class AddBottleLiquidAction extends OneWayAction { - private final IIngredient container; - private final ILiquidStack fill; - private final IItemStack output; - - public AddBottleLiquidAction(IIngredient container, ILiquidStack fill, IItemStack output) { - this.container = container; - this.fill = fill; - this.output = output; - } + @ZenMethod + public static void addEnrichRecipe(ILiquidStack output, ILiquidStack input, ILiquidStack additive) { + MineTweakerAPI.apply(new AddEnrichLiquidAction(input, additive, output)); + } - @Override - public void apply() { - Recipes.cannerBottle.addRecipe( - new IC2RecipeInput(container), - new RecipeInputFluidContainer( - ((FluidStack) fill.getInternal()).getFluid(), - fill.getAmount()), - getItemStack(output)); - } + private static class AddBottleIngredientAction extends OneWayAction { - @Override - public String describe() { - return "Adding cannor bottle recipe " + container + " + " + fill + " => " + output; - } + private final IIngredient container; + private final IIngredient fill; + private final IItemStack output; - @Override - public Object getOverrideKey() { - return null; - } - } - - private static class AddEnrichIngredientAction extends OneWayAction { - private final ILiquidStack input; - private final IIngredient additive; - private final ILiquidStack output; - - public AddEnrichIngredientAction(ILiquidStack input, IIngredient additive, ILiquidStack output) { - this.input = input; - this.additive = additive; - this.output = output; - } + public AddBottleIngredientAction(IIngredient container, IIngredient fill, IItemStack output) { + this.container = container; + this.fill = fill; + this.output = output; + } - @Override - public void apply() { - Recipes.cannerEnrich.addRecipe((FluidStack) input.getInternal(), new IC2RecipeInput(additive), (FluidStack) output.getInternal()); - } + @Override + public void apply() { + Recipes.cannerBottle.addRecipe(new IC2RecipeInput(container), new IC2RecipeInput(fill), getItemStack(output)); + } - @Override - public String describe() { - return "Adding canner enrich recipe " + input + " + " + additive + " => " + output; - } + @Override + public String describe() { + return "Adding canner bottle recipe " + container + " + " + fill + " => " + output; + } - @Override - public Object getOverrideKey() { - return null; - } + @Override + public Object getOverrideKey() { + return null; + } - @Override - public int hashCode() { - int hash = 7; - hash = 47 * hash + (this.input != null ? this.input.hashCode() : 0); - hash = 47 * hash + (this.additive != null ? this.additive.hashCode() : 0); - hash = 47 * hash + (this.output != null ? this.output.hashCode() : 0); - return hash; - } + @Override + public int hashCode() { + int hash = 7; + hash = 67 * hash + (this.container != null ? this.container.hashCode() : 0); + hash = 67 * hash + (this.fill != null ? this.fill.hashCode() : 0); + hash = 67 * hash + (this.output != null ? this.output.hashCode() : 0); + return hash; + } - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AddEnrichIngredientAction other = (AddEnrichIngredientAction) obj; - if (this.input != other.input && (this.input == null || !this.input.equals(other.input))) { - return false; - } - if (this.additive != other.additive && (this.additive == null || !this.additive.equals(other.additive))) { - return false; - } - if (this.output != other.output && (this.output == null || !this.output.equals(other.output))) { - return false; - } - return true; - } - } - - private static class AddEnrichLiquidAction extends OneWayAction { - private final ILiquidStack input; - private final ILiquidStack additive; - private final ILiquidStack output; - - public AddEnrichLiquidAction(ILiquidStack input, ILiquidStack additive, ILiquidStack output) { - this.input = input; - this.additive = additive; - this.output = output; - } + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final AddBottleIngredientAction other = (AddBottleIngredientAction) obj; + return !(this.container != other.container && (this.container == null || !this.container.equals(other.container))) && !(this.fill != other.fill && (this.fill == null || !this.fill.equals(other.fill))) && !(this.output != other.output && (this.output == null || !this.output.equals(other.output))); + } + } - @Override - public void apply() { - Recipes.cannerEnrich.addRecipe( - (FluidStack) input.getInternal(), new RecipeInputFluidContainer( - ((FluidStack) additive.getInternal()).getFluid(), - additive.getAmount()), - (FluidStack) output.getInternal()); - } + private static class AddBottleLiquidAction extends OneWayAction { - @Override - public String describe() { - return "Adding canner enrich recipe " + input + " + " + additive + " => " + output; - } + private final IIngredient container; + private final ILiquidStack fill; + private final IItemStack output; - @Override - public Object getOverrideKey() { - return null; - } + public AddBottleLiquidAction(IIngredient container, ILiquidStack fill, IItemStack output) { + this.container = container; + this.fill = fill; + this.output = output; + } - @Override - public int hashCode() { - int hash = 7; - hash = 19 * hash + (this.input != null ? this.input.hashCode() : 0); - hash = 19 * hash + (this.additive != null ? this.additive.hashCode() : 0); - hash = 19 * hash + (this.output != null ? this.output.hashCode() : 0); - return hash; - } + @Override + public void apply() { + Recipes.cannerBottle.addRecipe(new IC2RecipeInput(container), new RecipeInputFluidContainer(((FluidStack) fill.getInternal()).getFluid(), fill.getAmount()), getItemStack(output)); + } - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AddEnrichLiquidAction other = (AddEnrichLiquidAction) obj; - if (this.input != other.input && (this.input == null || !this.input.equals(other.input))) { - return false; - } - if (this.additive != other.additive && (this.additive == null || !this.additive.equals(other.additive))) { - return false; - } - if (this.output != other.output && (this.output == null || !this.output.equals(other.output))) { - return false; - } - return true; - } - } + @Override + public String describe() { + return "Adding cannor bottle recipe " + container + " + " + fill + " => " + output; + } + + @Override + public Object getOverrideKey() { + return null; + } + } + + private static class AddEnrichIngredientAction extends OneWayAction { + + private final ILiquidStack input; + private final IIngredient additive; + private final ILiquidStack output; + + public AddEnrichIngredientAction(ILiquidStack input, IIngredient additive, ILiquidStack output) { + this.input = input; + this.additive = additive; + this.output = output; + } + + @Override + public void apply() { + Recipes.cannerEnrich.addRecipe((FluidStack) input.getInternal(), new IC2RecipeInput(additive), (FluidStack) output.getInternal()); + } + + @Override + public String describe() { + return "Adding canner enrich recipe " + input + " + " + additive + " => " + output; + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + (this.input != null ? this.input.hashCode() : 0); + hash = 47 * hash + (this.additive != null ? this.additive.hashCode() : 0); + hash = 47 * hash + (this.output != null ? this.output.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final AddEnrichIngredientAction other = (AddEnrichIngredientAction) obj; + return !(this.input != other.input && (this.input == null || !this.input.equals(other.input))) && !(this.additive != other.additive && (this.additive == null || !this.additive.equals(other.additive))) && !(this.output != other.output && (this.output == null || !this.output.equals(other.output))); + } + } + + private static class AddEnrichLiquidAction extends OneWayAction { + + private final ILiquidStack input; + private final ILiquidStack additive; + private final ILiquidStack output; + + public AddEnrichLiquidAction(ILiquidStack input, ILiquidStack additive, ILiquidStack output) { + this.input = input; + this.additive = additive; + this.output = output; + } + + @Override + public void apply() { + Recipes.cannerEnrich.addRecipe((FluidStack) input.getInternal(), new RecipeInputFluidContainer(((FluidStack) additive.getInternal()).getFluid(), additive.getAmount()), (FluidStack) output.getInternal()); + } + + @Override + public String describe() { + return "Adding canner enrich recipe " + input + " + " + additive + " => " + output; + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 19 * hash + (this.input != null ? this.input.hashCode() : 0); + hash = 19 * hash + (this.additive != null ? this.additive.hashCode() : 0); + hash = 19 * hash + (this.output != null ? this.output.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final AddEnrichLiquidAction other = (AddEnrichLiquidAction) obj; + return !(this.input != other.input && (this.input == null || !this.input.equals(other.input))) && !(this.additive != other.additive && (this.additive == null || !this.additive.equals(other.additive))) && !(this.output != other.output && (this.output == null || !this.output.equals(other.output))); + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Compressor.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Compressor.java index 24bd1a6..a8de4b3 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Compressor.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Compressor.java @@ -1,69 +1,57 @@ package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; -import stanhebben.zenscript.annotations.NotNull; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.*; /** * Provides access to the IC2 compressor recipes. Recipes can be added but not * removed, due to IC2 API restrictions. - * + * * @author Stan Hebben */ @ZenClass("mods.ic2.Compressor") @ModOnly("IC2") public class Compressor { - /** - * Adds a new recipe to the compressor. - * - * The recipe input can be any pattern, as long as the stack size is determined. - * The output can be any item stack. - * - * @param output recipe output - * @param ingredient recipe input - */ - @ZenMethod - public static void addRecipe( - @NotNull IItemStack output, - @NotNull IIngredient ingredient) { - if (ingredient.getAmount() < 0) { - MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); - } else { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "compressor", - Recipes.compressor, - getItemStacks(output), - null, - new IC2RecipeInput(ingredient))); - } - } - - /** - * Determines the recipe output for the given input. Will return the output - * of a single item, even if the stack contains multiple items. - * - * @param input recipe input - * @return recipe output - */ - @ZenMethod - public static IItemStack getOutput( - @NotNull IItemStack input) { - RecipeOutput output = Recipes.compressor.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) { - System.out.println("No output"); - return null; - } - return getIItemStack(output.items.get(0)); - } + + /** + * Adds a new recipe to the compressor. + *

+ * The recipe input can be any pattern, as long as the stack size is determined. + * The output can be any item stack. + * + * @param output recipe output + * @param ingredient recipe input + */ + @ZenMethod + public static void addRecipe(@NotNull IItemStack output, @NotNull IIngredient ingredient) { + if(ingredient.getAmount() < 0) { + MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); + } else { + MineTweakerAPI.apply(new MachineAddRecipeAction("compressor", Recipes.compressor, getItemStacks(output), null, new IC2RecipeInput(ingredient))); + } + } + + /** + * Determines the recipe output for the given input. Will return the output + * of a single item, even if the stack contains multiple items. + * + * @param input recipe input + * + * @return recipe output + */ + @ZenMethod + public static IItemStack getOutput(@NotNull IItemStack input) { + RecipeOutput output = Recipes.compressor.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) { + System.out.println("No output"); + return null; + } + return getIItemStack(output.items.get(0)); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Extractor.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Extractor.java index f83590a..3a5cdbf 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Extractor.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Extractor.java @@ -1,71 +1,54 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; -import stanhebben.zenscript.annotations.NotNull; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.*; /** * Provides access to the IC2 Extractor recipes. - * + * * @author Stan Hebben */ @ZenClass("mods.ic2.Extractor") @ModOnly("IC2") public class Extractor { - /** - * Adds a new recipe to the extractor. - * - * The recipe input can be any pattern, as long as the stack size is determined. - * The output can be any item stack. - * - * @param output recipe output - * @param ingredient recipe input - */ - @ZenMethod - public static void addRecipe( - @NotNull IItemStack output, - @NotNull IIngredient ingredient) { - if (ingredient.getAmount() < 0) { - MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); - } else { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "extractor", - Recipes.extractor, - getItemStacks(output), - null, - new IC2RecipeInput(ingredient))); - } - } - - /** - * Determines the recipe output for the given input. Will return the output - * of a single item, even if the stack contains multiple items. - * - * @param input recipe input - * @return recipe output - */ - @ZenMethod - public static IItemStack getOutput( - @NotNull IItemStack input) { - RecipeOutput output = Recipes.extractor.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStack(output.items.get(0)); - } + + /** + * Adds a new recipe to the extractor. + *

+ * The recipe input can be any pattern, as long as the stack size is determined. + * The output can be any item stack. + * + * @param output recipe output + * @param ingredient recipe input + */ + @ZenMethod + public static void addRecipe(@NotNull IItemStack output, @NotNull IIngredient ingredient) { + if(ingredient.getAmount() < 0) { + MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); + } else { + MineTweakerAPI.apply(new MachineAddRecipeAction("extractor", Recipes.extractor, getItemStacks(output), null, new IC2RecipeInput(ingredient))); + } + } + + /** + * Determines the recipe output for the given input. Will return the output + * of a single item, even if the stack contains multiple items. + * + * @param input recipe input + * + * @return recipe output + */ + @ZenMethod + public static IItemStack getOutput(@NotNull IItemStack input) { + RecipeOutput output = Recipes.extractor.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStack(output.items.get(0)); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/FluidHeatGenerator.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/FluidHeatGenerator.java index 92df442..322ff57 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/FluidHeatGenerator.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/FluidHeatGenerator.java @@ -1,91 +1,77 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; import ic2.api.recipe.Recipes; -import minetweaker.MineTweakerAPI; -import minetweaker.OneWayAction; +import minetweaker.*; import minetweaker.annotations.ModOnly; import minetweaker.api.liquid.ILiquidStack; import net.minecraftforge.fluids.FluidRegistry; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; /** * Add a fluid to the fluid heat generator + * * @author Stan */ @ZenClass("mods.ic2.FluidHeatGenerator") @ModOnly("IC2") public class FluidHeatGenerator { - @ZenMethod - public static void addFluid(ILiquidStack liquidPerTick, int heatPerTick) { - MineTweakerAPI.apply(new AddFluidAction(liquidPerTick.getName(), liquidPerTick.getAmount(), heatPerTick)); - } - - @ZenMethod - public static boolean accepts(ILiquidStack liquid) { - return Recipes.fluidHeatGenerator.acceptsFluid(FluidRegistry.getFluid(liquid.getName())); - } - - private static class AddFluidAction extends OneWayAction { - private final String name; - private final int liquidPerTick; - private final int heatPerTick; - - public AddFluidAction(String name, int liquidPerTick, int heatPerTick) { - this.name = name; - this.liquidPerTick = liquidPerTick; - this.heatPerTick = heatPerTick; - } - - @Override - public void apply() { - Recipes.fluidHeatGenerator.addFluid(name, liquidPerTick, heatPerTick); - } - - @Override - public String describe() { - return "Adding liquid " + name + " as fluid heat generator fuel"; - } - - @Override - public Object getOverrideKey() { - return null; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 47 * hash + this.liquidPerTick; - hash = 47 * hash + this.heatPerTick; - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AddFluidAction other = (AddFluidAction) obj; - if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { - return false; - } - if (this.liquidPerTick != other.liquidPerTick) { - return false; - } - if (this.heatPerTick != other.heatPerTick) { - return false; - } - return true; - } - } + + @ZenMethod + public static void addFluid(ILiquidStack liquidPerTick, int heatPerTick) { + MineTweakerAPI.apply(new AddFluidAction(liquidPerTick.getName(), liquidPerTick.getAmount(), heatPerTick)); + } + + @ZenMethod + public static boolean accepts(ILiquidStack liquid) { + return Recipes.fluidHeatGenerator.acceptsFluid(FluidRegistry.getFluid(liquid.getName())); + } + + private static class AddFluidAction extends OneWayAction { + + private final String name; + private final int liquidPerTick; + private final int heatPerTick; + + public AddFluidAction(String name, int liquidPerTick, int heatPerTick) { + this.name = name; + this.liquidPerTick = liquidPerTick; + this.heatPerTick = heatPerTick; + } + + @Override + public void apply() { + Recipes.fluidHeatGenerator.addFluid(name, liquidPerTick, heatPerTick); + } + + @Override + public String describe() { + return "Adding liquid " + name + " as fluid heat generator fuel"; + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 47 * hash + this.liquidPerTick; + hash = 47 * hash + this.heatPerTick; + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final AddFluidAction other = (AddFluidAction) obj; + return (this.name == null) ? other.name == null : this.name.equals(other.name) && this.liquidPerTick == other.liquidPerTick && this.heatPerTick == other.heatPerTick; + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Macerator.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Macerator.java index d985d16..359f220 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Macerator.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Macerator.java @@ -1,66 +1,55 @@ package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; -import stanhebben.zenscript.annotations.NotNull; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.*; /** * Provides access to the IC2 macerator recipes. Recipes can be added but not * removed, due to IC2 API restrictions. - * + * * @author Stan Hebben */ @ZenClass("mods.ic2.Macerator") @ModOnly("IC2") public class Macerator { - /** - * Adds a new recipe to the macerator. - * - * The recipe input can be any pattern, as long as the stack size is determined. - * The output can be any item stack. - * - * @param output recipe output - * @param ingredient recipe input - */ - @ZenMethod - public static void addRecipe( - @NotNull IItemStack output, - @NotNull IIngredient ingredient) { - if (ingredient.getAmount() < 0) { - MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); - } else { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "macerator", - Recipes.macerator, - getItemStacks(output), - null, - new IC2RecipeInput(ingredient))); - } - } - - /** - * Determines the recipe output for the given input. Will return the output - * of a single item, even if the stack contains multiple items. - * - * @param input recipe input - * @return recipe output - */ - @ZenMethod - public static IItemStack getOutput( - @NotNull IItemStack input) { - RecipeOutput output = Recipes.macerator.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStack(output.items.get(0)); - } + + /** + * Adds a new recipe to the macerator. + *

+ * The recipe input can be any pattern, as long as the stack size is determined. + * The output can be any item stack. + * + * @param output recipe output + * @param ingredient recipe input + */ + @ZenMethod + public static void addRecipe(@NotNull IItemStack output, @NotNull IIngredient ingredient) { + if(ingredient.getAmount() < 0) { + MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); + } else { + MineTweakerAPI.apply(new MachineAddRecipeAction("macerator", Recipes.macerator, getItemStacks(output), null, new IC2RecipeInput(ingredient))); + } + } + + /** + * Determines the recipe output for the given input. Will return the output + * of a single item, even if the stack contains multiple items. + * + * @param input recipe input + * + * @return recipe output + */ + @ZenMethod + public static IItemStack getOutput(@NotNull IItemStack input) { + RecipeOutput output = Recipes.macerator.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStack(output.items.get(0)); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MatterAmplifier.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MatterAmplifier.java index 1a63967..7caae01 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MatterAmplifier.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MatterAmplifier.java @@ -1,35 +1,28 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; import ic2.api.recipe.Recipes; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; import minetweaker.api.item.IIngredient; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; +import minetweaker.mods.ic2.*; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; /** - * * @author Stan */ @ZenClass("mods.ic2.MatterAmplifier") @ModOnly("IC2") public class MatterAmplifier { - private MatterAmplifier() {} - - @ZenMethod - public static void setAmplifier(IIngredient item, int amplifier) { - NBTTagCompound data = new NBTTagCompound(); - data.setInteger("amplification", amplifier); - MineTweakerAPI.apply(new MachineAddRecipeAction("matter amplifier", Recipes.matterAmplifier, new ItemStack[0], data, new IC2RecipeInput(item))); - } + + private MatterAmplifier() { + } + + @ZenMethod + public static void setAmplifier(IIngredient item, int amplifier) { + NBTTagCompound data = new NBTTagCompound(); + data.setInteger("amplification", amplifier); + MineTweakerAPI.apply(new MachineAddRecipeAction("matter amplifier", Recipes.matterAmplifier, new ItemStack[0], data, new IC2RecipeInput(item))); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MetalFormer.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MetalFormer.java index 774f081..144a804 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MetalFormer.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/MetalFormer.java @@ -1,115 +1,96 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.*; /** - * * @author Stan Hebben */ @ZenClass("mods.ic2.MetalFormer") @ModOnly("IC2") public class MetalFormer { - /** - * Adds an extruding recipe to the metal former. - * - * @param output output item - * @param input input item - */ - @ZenMethod - public static void addExtrudingRecipe(IItemStack output, IIngredient input) { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "metal former - extruding", - Recipes.metalformerExtruding, - getItemStacks(output), - null, - new IC2RecipeInput(input))); - } - - /** - * Gets the extruding output for the given input. - * - * @param input input item - * @return output item, or null - */ - @ZenMethod - public static IItemStack getExtrudingOutput(IItemStack input) { - RecipeOutput output = Recipes.metalformerExtruding.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStack(output.items.get(0)); - } - - /** - * Adds a rolling recipe to the metal former. - * - * @param output output item - * @param input input item - */ - @ZenMethod - public static void addRollingRecipe(IItemStack output, IIngredient input) { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "metal former - rolling", - Recipes.metalformerRolling, - getItemStacks(output), - null, - new IC2RecipeInput(input))); - } - - /** - * Gets the extruding output for the given input. - * - * @param input input item - * @return output item, or null - */ - @ZenMethod - public static IItemStack getRollingOutput(IItemStack input) { - RecipeOutput output = Recipes.metalformerRolling.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStack(output.items.get(0)); - } - /** - * Adds a extruding recipe to the metal former. - * - * @param output output item - * @param input input item - */ - @ZenMethod - public static void addCuttingRecipe(IItemStack output, IIngredient input) { - MineTweakerAPI.apply(new MachineAddRecipeAction( - "metal former - cutting", - Recipes.metalformerCutting, - getItemStacks(output), - null, - new IC2RecipeInput(input))); - } - - /** - * Gets the cutting output for the given input. - * - * @param input input item - * @return output item, or null - */ - @ZenMethod - public static IItemStack getCuttingOutput(IItemStack input) { - RecipeOutput output = Recipes.metalformerCutting.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStack(output.items.get(0)); - } + + /** + * Adds an extruding recipe to the metal former. + * + * @param output output item + * @param input input item + */ + @ZenMethod + public static void addExtrudingRecipe(IItemStack output, IIngredient input) { + MineTweakerAPI.apply(new MachineAddRecipeAction("metal former - extruding", Recipes.metalformerExtruding, getItemStacks(output), null, new IC2RecipeInput(input))); + } + + /** + * Gets the extruding output for the given input. + * + * @param input input item + * + * @return output item, or null + */ + @ZenMethod + public static IItemStack getExtrudingOutput(IItemStack input) { + RecipeOutput output = Recipes.metalformerExtruding.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStack(output.items.get(0)); + } + + /** + * Adds a rolling recipe to the metal former. + * + * @param output output item + * @param input input item + */ + @ZenMethod + public static void addRollingRecipe(IItemStack output, IIngredient input) { + MineTweakerAPI.apply(new MachineAddRecipeAction("metal former - rolling", Recipes.metalformerRolling, getItemStacks(output), null, new IC2RecipeInput(input))); + } + + /** + * Gets the extruding output for the given input. + * + * @param input input item + * + * @return output item, or null + */ + @ZenMethod + public static IItemStack getRollingOutput(IItemStack input) { + RecipeOutput output = Recipes.metalformerRolling.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStack(output.items.get(0)); + } + + /** + * Adds a extruding recipe to the metal former. + * + * @param output output item + * @param input input item + */ + @ZenMethod + public static void addCuttingRecipe(IItemStack output, IIngredient input) { + MineTweakerAPI.apply(new MachineAddRecipeAction("metal former - cutting", Recipes.metalformerCutting, getItemStacks(output), null, new IC2RecipeInput(input))); + } + + /** + * Gets the cutting output for the given input. + * + * @param input input item + * + * @return output item, or null + */ + @ZenMethod + public static IItemStack getCuttingOutput(IItemStack input) { + RecipeOutput output = Recipes.metalformerCutting.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStack(output.items.get(0)); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/OreWasher.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/OreWasher.java index a0af2f9..e95484a 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/OreWasher.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/OreWasher.java @@ -1,43 +1,34 @@ package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStacks; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; import net.minecraft.nbt.NBTTagCompound; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.*; /** - * * @author Stan Hebben */ @ZenClass("mods.ic2.OreWasher") @ModOnly("IC2") public class OreWasher { - @ZenMethod - public static void addRecipe(IItemStack[] output, IIngredient input, int millibuckets) { - NBTTagCompound nbt = new NBTTagCompound(); - nbt.setInteger("amount", millibuckets); - MineTweakerAPI.apply(new MachineAddRecipeAction( - "ore washer", - Recipes.oreWashing, - getItemStacks(output), - nbt, - new IC2RecipeInput(input))); - } - - @ZenMethod - public static IItemStack[] getOutput(IItemStack input) { - RecipeOutput output = Recipes.oreWashing.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStacks(output.items); - } + + @ZenMethod + public static void addRecipe(IItemStack[] output, IIngredient input, int millibuckets) { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("amount", millibuckets); + MineTweakerAPI.apply(new MachineAddRecipeAction("ore washer", Recipes.oreWashing, getItemStacks(output), nbt, new IC2RecipeInput(input))); + } + + @ZenMethod + public static IItemStack[] getOutput(IItemStack input) { + RecipeOutput output = Recipes.oreWashing.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStacks(output.items); + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Recycler.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Recycler.java index d7d1d29..23aba6f 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Recycler.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/Recycler.java @@ -1,81 +1,71 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; import ic2.api.recipe.Recipes; -import minetweaker.MineTweakerAPI; -import minetweaker.OneWayAction; +import minetweaker.*; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; +import minetweaker.api.item.*; import minetweaker.mods.ic2.IC2RecipeInput; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; /** - * * @author Stan */ @ZenClass("mods.ic2.Recycler") @ModOnly("IC2") public class Recycler { - @ZenMethod - public static void addBlacklist(IIngredient ingredient) { - MineTweakerAPI.apply(new AddBlacklistAction(ingredient)); - } - - @ZenMethod - public static boolean isBlacklisted(IItemStack item) { - return Recipes.recyclerBlacklist.contains(getItemStack(item)); - } - - private static class AddBlacklistAction extends OneWayAction { - private IIngredient ingredient; - - public AddBlacklistAction(IIngredient ingredient) { - this.ingredient = ingredient; - } - @Override - public void apply() { - Recipes.recyclerBlacklist.add(new IC2RecipeInput(ingredient)); - } + @ZenMethod + public static void addBlacklist(IIngredient ingredient) { + MineTweakerAPI.apply(new AddBlacklistAction(ingredient)); + } - @Override - public String describe() { - return "Adding " + ingredient + " to the recycler blacklist"; - } + @ZenMethod + public static boolean isBlacklisted(IItemStack item) { + return Recipes.recyclerBlacklist.contains(getItemStack(item)); + } - @Override - public Object getOverrideKey() { - return null; - } + private static class AddBlacklistAction extends OneWayAction { - @Override - public int hashCode() { - int hash = 3; - hash = 29 * hash + (this.ingredient != null ? this.ingredient.hashCode() : 0); - return hash; - } + private IIngredient ingredient; - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AddBlacklistAction other = (AddBlacklistAction) obj; - if (this.ingredient != other.ingredient && (this.ingredient == null || !this.ingredient.equals(other.ingredient))) { - return false; - } - return true; - } - } + public AddBlacklistAction(IIngredient ingredient) { + this.ingredient = ingredient; + } + + @Override + public void apply() { + Recipes.recyclerBlacklist.add(new IC2RecipeInput(ingredient)); + } + + @Override + public String describe() { + return "Adding " + ingredient + " to the recycler blacklist"; + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 29 * hash + (this.ingredient != null ? this.ingredient.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final AddBlacklistAction other = (AddBlacklistAction) obj; + return !(this.ingredient != other.ingredient && (this.ingredient == null || !this.ingredient.equals(other.ingredient))); + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ScrapBox.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ScrapBox.java index 943ff5c..a68eb04 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ScrapBox.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ScrapBox.java @@ -1,90 +1,81 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; import ic2.api.recipe.Recipes; -import minetweaker.MineTweakerAPI; -import minetweaker.OneWayAction; +import minetweaker.*; import minetweaker.annotations.ModOnly; import minetweaker.api.item.WeightedItemStack; +import stanhebben.zenscript.annotations.*; + import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; /** - * * @author Stan */ @ZenClass("mods.ic2.ScrapBox") @ModOnly("IC2") public class ScrapBox { - /** - * Adds an item drop. - * - * Reference scrap box chance values: - * - * 0.1: Diamond - * 0.5: Cake, Gold Helmet, Iron Ore, Gold Ore - * 1.0: Wooden tools, Soul Sand, Sign, Leather, Feather, Bone - * 1.5: Apple, Bread - * 2.0: Netherrack, Rotten Flesh - * 3.0: Grass, Gravel - * 4.0: Stick - * 5.0: Dirt, Wooden Hoe - * - * @param stack weighted item stack to add - */ - @ZenMethod - public static void addDrop(WeightedItemStack stack) { - MineTweakerAPI.apply(new AddDropAction(stack)); - } - - private static class AddDropAction extends OneWayAction { - private final WeightedItemStack stack; - - public AddDropAction(WeightedItemStack stack) { - this.stack = stack; - } - @Override - public void apply() { - Recipes.scrapboxDrops.addDrop(getItemStack(stack.getStack()), stack.getChance()); - } + /** + * Adds an item drop. + *

+ * Reference scrap box chance values: + *

+ * 0.1: Diamond + * 0.5: Cake, Gold Helmet, Iron Ore, Gold Ore + * 1.0: Wooden tools, Soul Sand, Sign, Leather, Feather, Bone + * 1.5: Apple, Bread + * 2.0: Netherrack, Rotten Flesh + * 3.0: Grass, Gravel + * 4.0: Stick + * 5.0: Dirt, Wooden Hoe + * + * @param stack weighted item stack to add + */ + @ZenMethod + public static void addDrop(WeightedItemStack stack) { + MineTweakerAPI.apply(new AddDropAction(stack)); + } - @Override - public String describe() { - return "Adding scrapbox drop " + stack.getStack(); - } + private static class AddDropAction extends OneWayAction { - @Override - public Object getOverrideKey() { - return null; - } + private final WeightedItemStack stack; - @Override - public int hashCode() { - int hash = 5; - hash = 71 * hash + (this.stack != null ? this.stack.hashCode() : 0); - return hash; - } + public AddDropAction(WeightedItemStack stack) { + this.stack = stack; + } - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AddDropAction other = (AddDropAction) obj; - if (this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))) { - return false; - } - return true; - } - } + @Override + public void apply() { + Recipes.scrapboxDrops.addDrop(getItemStack(stack.getStack()), stack.getChance()); + } + + @Override + public String describe() { + return "Adding scrapbox drop " + stack.getStack(); + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 71 * hash + (this.stack != null ? this.stack.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final AddDropAction other = (AddDropAction) obj; + return !(this.stack != other.stack && (this.stack == null || !this.stack.equals(other.stack))); + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/SemiFluidGenerator.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/SemiFluidGenerator.java index 348713c..c23bfb5 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/SemiFluidGenerator.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/SemiFluidGenerator.java @@ -1,91 +1,77 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - package minetweaker.mods.ic2.machines; import ic2.api.recipe.Recipes; -import minetweaker.MineTweakerAPI; -import minetweaker.OneWayAction; +import minetweaker.*; import minetweaker.annotations.ModOnly; import minetweaker.api.liquid.ILiquidStack; import net.minecraftforge.fluids.FluidRegistry; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; /** * Add a fluid to the semi-fluid generator + * * @author Stan */ @ZenClass("mods.ic2.SemiFluidGenerator") @ModOnly("IC2") public class SemiFluidGenerator { - @ZenMethod - public static void addFluid(ILiquidStack liquidPerTick, int energyPerTick) { - MineTweakerAPI.apply(new AddFluidAction(liquidPerTick.getName(), liquidPerTick.getAmount(), energyPerTick)); - } - - @ZenMethod - public static boolean accepts(ILiquidStack liquid) { - return Recipes.semiFluidGenerator.acceptsFluid(FluidRegistry.getFluid(liquid.getName())); - } - - private static class AddFluidAction extends OneWayAction { - private final String name; - private final int liquidPerTick; - private final int energyPerTick; - - public AddFluidAction(String name, int liquidPerTick, int energyPerTick) { - this.name = name; - this.liquidPerTick = liquidPerTick; - this.energyPerTick = energyPerTick; - } - - @Override - public void apply() { - Recipes.semiFluidGenerator.addFluid(name, liquidPerTick, energyPerTick); - } - - @Override - public String describe() { - return "Adding liquid " + name + " as semifluid fuel"; - } - - @Override - public Object getOverrideKey() { - return null; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 47 * hash + this.liquidPerTick; - hash = 47 * hash + this.energyPerTick; - return hash; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final AddFluidAction other = (AddFluidAction) obj; - if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { - return false; - } - if (this.liquidPerTick != other.liquidPerTick) { - return false; - } - if (this.energyPerTick != other.energyPerTick) { - return false; - } - return true; - } - } + + @ZenMethod + public static void addFluid(ILiquidStack liquidPerTick, int energyPerTick) { + MineTweakerAPI.apply(new AddFluidAction(liquidPerTick.getName(), liquidPerTick.getAmount(), energyPerTick)); + } + + @ZenMethod + public static boolean accepts(ILiquidStack liquid) { + return Recipes.semiFluidGenerator.acceptsFluid(FluidRegistry.getFluid(liquid.getName())); + } + + private static class AddFluidAction extends OneWayAction { + + private final String name; + private final int liquidPerTick; + private final int energyPerTick; + + public AddFluidAction(String name, int liquidPerTick, int energyPerTick) { + this.name = name; + this.liquidPerTick = liquidPerTick; + this.energyPerTick = energyPerTick; + } + + @Override + public void apply() { + Recipes.semiFluidGenerator.addFluid(name, liquidPerTick, energyPerTick); + } + + @Override + public String describe() { + return "Adding liquid " + name + " as semifluid fuel"; + } + + @Override + public Object getOverrideKey() { + return null; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 47 * hash + this.liquidPerTick; + hash = 47 * hash + this.energyPerTick; + return hash; + } + + @Override + public boolean equals(Object obj) { + if(obj == null) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + final AddFluidAction other = (AddFluidAction) obj; + return (this.name == null) ? other.name == null : this.name.equals(other.name) && this.liquidPerTick == other.liquidPerTick && this.energyPerTick == other.energyPerTick; + } + } } diff --git a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ThermalCentrifuge.java b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ThermalCentrifuge.java index 9d7accf..cc9874e 100644 --- a/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ThermalCentrifuge.java +++ b/MineTweaker3-MC1102-Mod-IC2/src/main/java/minetweaker/mods/ic2/machines/ThermalCentrifuge.java @@ -1,81 +1,74 @@ package minetweaker.mods.ic2.machines; -import ic2.api.recipe.RecipeOutput; -import ic2.api.recipe.Recipes; +import ic2.api.recipe.*; import minetweaker.MineTweakerAPI; import minetweaker.annotations.ModOnly; -import minetweaker.api.item.IIngredient; -import minetweaker.api.item.IItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getIItemStacks; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.api.minecraft.MineTweakerMC.getItemStacks; +import minetweaker.api.item.*; +import minetweaker.mods.ic2.*; import net.minecraft.nbt.NBTTagCompound; -import minetweaker.mods.ic2.IC2RecipeInput; -import minetweaker.mods.ic2.MachineAddRecipeAction; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; +import stanhebben.zenscript.annotations.*; + +import static minetweaker.api.minecraft.MineTweakerMC.*; /** * Provides access to the IC2 compressor recipes. Recipes can be added but not * removed, due to IC2 API restrictions. - * + * * @author Stan Hebben */ @ZenClass("mods.ic2.ThermalCentrifuge") @ModOnly("IC2") public class ThermalCentrifuge { - /** - * Adds a new recipe to the centrifuge. - * - * The recipe input can be any ingredient, as long as the stack size is determined. - * The output is an array of item stacks. - * - * @param output recipe outputs - * @param ingredient recipe input - * @param minHeat minimum centrifuge heat level - */ - @ZenMethod - public static void addRecipe(IItemStack[] output, IIngredient ingredient, int minHeat) { - if (ingredient.getAmount() < 0) { - MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); - } else { - NBTTagCompound tag = new NBTTagCompound(); - tag.setInteger("minHeat", minHeat); - MineTweakerAPI.apply(new MachineAddRecipeAction( - "thermal centrifuge", - Recipes.centrifuge, - getItemStacks(output), - tag, - new IC2RecipeInput(ingredient))); - } - } - - /** - * Adds a new recipe to the centrifuge. - * - * The recipe input can be any ingredient, as long as the stack size is determined. - * The output can be any item stack. - * - * @param output recipe output - * @param ingredient recipe input - * @param minHeat minimum centrifuge heat level - */ - @ZenMethod - public static void addRecipe(IItemStack output, IIngredient ingredient, int minHeat) { - addRecipe(new IItemStack[] { output }, ingredient, minHeat); - } - - /** - * Determines the recipe output for the given input. Will return the output - * of a single item, even if the stack contains multiple items. - * - * @param input recipe input - * @return recipe output - */ - @ZenMethod - public static IItemStack[] getOutput(IItemStack input) { - RecipeOutput output = Recipes.centrifuge.getOutputFor(getItemStack(input), false); - if (output == null || output.items.isEmpty()) return null; - return getIItemStacks(output.items); - } + + /** + * Adds a new recipe to the centrifuge. + *

+ * The recipe input can be any ingredient, as long as the stack size is determined. + * The output is an array of item stacks. + * + * @param output recipe outputs + * @param ingredient recipe input + * @param minHeat minimum centrifuge heat level + */ + @ZenMethod + public static void addRecipe(IItemStack[] output, IIngredient ingredient, int minHeat) { + if(ingredient.getAmount() < 0) { + MineTweakerAPI.logWarning("invalid ingredient: " + ingredient + " - stack size not known"); + } else { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("minHeat", minHeat); + MineTweakerAPI.apply(new MachineAddRecipeAction("thermal centrifuge", Recipes.centrifuge, getItemStacks(output), tag, new IC2RecipeInput(ingredient))); + } + } + + /** + * Adds a new recipe to the centrifuge. + *

+ * The recipe input can be any ingredient, as long as the stack size is determined. + * The output can be any item stack. + * + * @param output recipe output + * @param ingredient recipe input + * @param minHeat minimum centrifuge heat level + */ + @ZenMethod + public static void addRecipe(IItemStack output, IIngredient ingredient, int minHeat) { + addRecipe(new IItemStack[]{output}, ingredient, minHeat); + } + + /** + * Determines the recipe output for the given input. Will return the output + * of a single item, even if the stack contains multiple items. + * + * @param input recipe input + * + * @return recipe output + */ + @ZenMethod + public static IItemStack[] getOutput(IItemStack input) { + RecipeOutput output = Recipes.centrifuge.getOutputFor(getItemStack(input), false); + if(output == null || output.items.isEmpty()) + return null; + return getIItemStacks(output.items); + } } diff --git a/MineTweaker3-MC1102-Mod-JEI/build.gradle b/MineTweaker3-MC1102-Mod-JEI/build.gradle index 43d4c50..9be95dd 100644 --- a/MineTweaker3-MC1102-Mod-JEI/build.gradle +++ b/MineTweaker3-MC1102-Mod-JEI/build.gradle @@ -1,7 +1,6 @@ import minetweaker.tasks.RegisterZenClassesTask; - buildscript { repositories { mavenCentral() @@ -13,10 +12,10 @@ buildscript { name = "sonatype" url = "https://oss.sonatype.org/content/repositories/snapshots/" } - + } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' } } apply plugin: 'net.minecraftforge.gradle.forge' @@ -28,28 +27,28 @@ version = "1.10.2-" + ext.mineTweakerVersion archivesBaseName = project.projectDir.name minecraft { - version = forgeVersion1102 - runDir = "eclipse" - mappings = "snapshot_20160518" - useDepAts = true - } + version = forgeVersion1102 + runDir = "eclipse" + mappings = "stable_29" + useDepAts = true +} repositories { - maven { - url "http://dvs1.progwml6.com/files/maven" - } + maven { + url "http://dvs1.progwml6.com/files/maven" + } } dependencies { - compile project(':ZenScript') - compile project(':MineTweaker3-API') - compile project(':MineTweaker3-MC1102-Main') - compile "mezz.jei:jei_1.10.2:3.9.7.260" + compile project(':ZenScript') + compile project(':MineTweaker3-API') + compile project(':MineTweaker3-MC1102-Main') + compile "mezz.jei:jei_1.10.2:3.14.2.398" } task makeRegistry(type: RegisterZenClassesTask) { - inputDir = file('build/classes/main') - outputDir = file('build/classes/main') - className = 'minetweaker.mods.jei.ClassRegistry' + inputDir = file('build/classes/main') + outputDir = file('build/classes/main') + className = 'minetweaker.mods.jei.ClassRegistry' } tasks.jar.dependsOn(makeRegistry) diff --git a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java index 34d2582..313d30e 100644 --- a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java +++ b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java @@ -1,20 +1,11 @@ package minetweaker.mods.jei; -import minetweaker.IUndoableAction; -import minetweaker.MineTweakerAPI; -import minetweaker.MineTweakerImplementationAPI; -import minetweaker.annotations.OnRegister; +import minetweaker.*; import minetweaker.api.item.IItemStack; -import minetweaker.util.IEventHandler; -import net.minecraftforge.fml.common.Loader; -import stanhebben.zenscript.annotations.NotNull; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; - -import java.util.LinkedList; +import net.minecraft.item.ItemStack; +import stanhebben.zenscript.annotations.*; import static minetweaker.api.minecraft.MineTweakerMC.getItemStack; -import static minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers; /** * MineTweaker JEI support. @@ -28,109 +19,47 @@ import static minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers; */ @ZenClass("mods.jei.JEI") public class JEI { - - /** - * Hides a specific item in JEI. Will take into account metadata values, if - * any. - * - * @param item item to be hidden - */ + @ZenMethod - public static void hide(@NotNull IItemStack item) { - MineTweakerAPI.apply(new JEIHideItemAction(item)); + public static void hide(IItemStack stack) { + MineTweakerAPI.apply(new Hide(getItemStack(stack))); } - - /** - * Register callbacks otherwise the load order with JEI is all messed up. - */ - @OnRegister - public static void onRegister() { - // discard all not yet applied actions before a reload - MineTweakerImplementationAPI.onReloadEvent(new IEventHandler() { - @Override - public void handle(MineTweakerImplementationAPI.ReloadEvent event) { - apply.clear(); - } - }); - - // after the reload JEI needs to be reloaded as well - MineTweakerImplementationAPI.onPostReload(new IEventHandler() { - @Override - public void handle(MineTweakerImplementationAPI.ReloadEvent event) { - if (Loader.isModLoaded("JEI")) { - try { - if (Class.forName("minetweaker.mods.jei.JEIAddonPlugin") != null) { - System.out.println("class exists"); - } - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - if (minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers != null) - minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers.reload(); - } - } - }); - } - - // list of all hide actions that need to be applied after JEI is available - private static LinkedList apply = new LinkedList(); - - /** - * JEI is available and the Hiding of the actions can now be applied. - */ - public static void onJEIStarted() { - for (JEIHideItemAction action : apply) { - action.doApply(); - } - apply.clear(); - } - - private static class JEIHideItemAction implements IUndoableAction { - private final IItemStack stack; - - public JEIHideItemAction(IItemStack stack) { + + private static class Hide implements IUndoableAction { + + private ItemStack stack; + + public Hide(ItemStack stack) { this.stack = stack; } - + @Override public void apply() { - // just register until the JEI addon is registered, otherwise the jeiHelpers are null - apply.add(this); + if(!JEIAddonPlugin.jeiHelpers.getIngredientBlacklist().isIngredientBlacklisted(stack)) + JEIAddonPlugin.jeiHelpers.getIngredientBlacklist().addIngredientToBlacklist(stack); } - - /** - * Really adds the item to the blacklist when JEI is available - */ - void doApply() { - if (jeiHelpers != null) { - jeiHelpers.getItemBlacklist().addItemToBlacklist(getItemStack(stack)); - } else { - // Should not happen, but in case only log an error - MineTweakerImplementationAPI.logger.logError("JEI not initialized yet!"); - } - } - + @Override public boolean canUndo() { return true; } - + @Override public void undo() { - // Doesn't need to be called since on reload of JEI the blacklist will be cleared anyway - // jeiHelpers.getItemBlacklist().removeItemFromBlacklist(getItemStack(stack)); + if(JEIAddonPlugin.jeiHelpers.getIngredientBlacklist().isIngredientBlacklisted(stack)) + JEIAddonPlugin.jeiHelpers.getIngredientBlacklist().removeIngredientFromBlacklist(stack); } - + @Override public String describe() { - return "Hiding " + stack + " in JEI"; + return "Hiding item in JEI: " + stack; } - + @Override public String describeUndo() { - return "Displaying " + stack + " in JEI"; + return "Displaying item in JEI: " + stack; } - + @Override public Object getOverrideKey() { return null; diff --git a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIAddonPlugin.java b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIAddonPlugin.java index 2d876df..84ae174 100644 --- a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIAddonPlugin.java +++ b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIAddonPlugin.java @@ -1,29 +1,45 @@ package minetweaker.mods.jei; +import mezz.jei.Internal; import mezz.jei.api.*; +import mezz.jei.api.ingredients.*; +import minetweaker.MineTweakerAPI; +import minetweaker.api.compat.DummyJEIRecipeRegistry; @mezz.jei.api.JEIPlugin public class JEIAddonPlugin implements IModPlugin { + public static IJeiHelpers jeiHelpers; - public static IItemRegistry itemRegistry; + public static IIngredientRegistry itemRegistry; public static IRecipeRegistry recipeRegistry; - - + public static IItemListOverlay itemListOverlay; + + @Override + public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) { + + } + + @Override + public void registerIngredients(IModIngredientRegistration registry) { + + } + @Override public void register(IModRegistry registry) { jeiHelpers = registry.getJeiHelpers(); - itemRegistry = registry.getItemRegistry(); - - // The blacklist items must be registered here, otherwise the item filters are already created and - // anything that is added doesn't have an effect - JEI.onJEIStarted(); + itemRegistry = registry.getIngredientRegistry(); } - + @Override public void onRuntimeAvailable(IJeiRuntime iJeiRuntime) { recipeRegistry = iJeiRuntime.getRecipeRegistry(); + itemListOverlay = iJeiRuntime.getItemListOverlay(); + + if(MineTweakerAPI.getIjeiRecipeRegistry() instanceof DummyJEIRecipeRegistry) { + MineTweakerAPI.setIjeiRecipeRegistry(new JEIRecipeRegistry(recipeRegistry, jeiHelpers)); + } } - - + + } diff --git a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIMod.java b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIMod.java new file mode 100644 index 0000000..64f1561 --- /dev/null +++ b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIMod.java @@ -0,0 +1,15 @@ +package minetweaker.mods.jei; + +import minetweaker.MineTweakerAPI; +import net.minecraftforge.fml.common.*; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +@Mod(modid = "crafttweakerjei", name = "CraftTweaker JEI Support", version = "1.0.1", dependencies = "required-before:MineTweaker3;") +public class JEIMod { + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent ev) { + if(Loader.isModLoaded("JEI")) + MineTweakerAPI.registerClass(JEI.class); + } +} diff --git a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIRecipeRegistry.java b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIRecipeRegistry.java new file mode 100644 index 0000000..96eb276 --- /dev/null +++ b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEIRecipeRegistry.java @@ -0,0 +1,132 @@ +package minetweaker.mods.jei; + +import mezz.jei.IngredientInformation; +import mezz.jei.api.*; +import mezz.jei.api.recipe.*; +import mezz.jei.gui.ItemListOverlay; +import mezz.jei.plugins.vanilla.furnace.FuelRecipe; +import minetweaker.MineTweakerImplementationAPI; +import minetweaker.api.compat.IJEIRecipeRegistry; +import minetweaker.api.item.IIngredient; +import minetweaker.mc1102.util.MineTweakerHacks; +import minetweaker.util.IEventHandler; +import net.minecraft.item.ItemStack; + +import java.util.*; + +public class JEIRecipeRegistry implements IJEIRecipeRegistry { + + private IRecipeRegistry recipeRegistry; + private IJeiHelpers jeiHelpers; + private boolean shouldReloadItemList = false; + + private static Map TOOLTIP_CACHE; + + public JEIRecipeRegistry(IRecipeRegistry recipeRegistry, IJeiHelpers jeiHelpers) { + this.recipeRegistry = recipeRegistry; + this.jeiHelpers = jeiHelpers; + MineTweakerImplementationAPI.onPostReload(new ReloadHandler()); + } + + @Override + public void addRecipe(Object object) { + recipeRegistry.addRecipe(object); + } + + @Deprecated + @Override + public void addRecipe(Object object, String category) { + recipeRegistry.addRecipe(object); + } + + @Override + public void removeRecipe(Object object) { + recipeRegistry.removeRecipe(object); + } + + @Deprecated + @Override + public void removeRecipe(Object output, String category) { + recipeRegistry.removeRecipe(output); + } + + @Override + public void addFurnace(List input, Object output) { + List inputs = new ArrayList<>(); + input.forEach(in -> { + inputs.add((ItemStack) in); + }); + recipeRegistry.addSmeltingRecipe(inputs, (ItemStack) output); + } + + + @Override + public void removeFurnace(Object object) { + IFocus focus = recipeRegistry.createFocus(IFocus.Mode.INPUT, (ItemStack) object); + List categories = recipeRegistry.getRecipeCategories(focus); + for(IRecipeCategory category : categories) { + if(category.getUid().equals(VanillaRecipeCategoryUid.SMELTING)) { + List wrappers = recipeRegistry.getRecipeWrappers(category, focus); + for(IRecipeWrapper wrapper : wrappers) { + recipeRegistry.removeRecipe(wrapper); + } + } + } + } + + public void addFuel(Collection input, int burnTime){ + List inputs = new ArrayList<>(); + input.forEach(in -> { + inputs.add((ItemStack) in); + }); + recipeRegistry.addRecipe(new FuelRecipe(jeiHelpers.getGuiHelper(), inputs, burnTime)); + } + + public void removeFuel(Object object){ + IFocus focus = recipeRegistry.createFocus(IFocus.Mode.INPUT, (ItemStack) object); + List categories = recipeRegistry.getRecipeCategories(focus); + for(IRecipeCategory category : categories) { + if(category.getUid().equals(VanillaRecipeCategoryUid.FUEL)) { + List wrappers = recipeRegistry.getRecipeWrappers(category, focus); + for(IRecipeWrapper wrapper : wrappers) { + recipeRegistry.removeRecipe(wrapper); + } + } + } + } + + @Override + public void reloadItemList() { + shouldReloadItemList = true; + } + + //Unused in 1.10.2 + @Override + public void removeItem(Object stack) {} + + //Unused in 1.10.2 + @Override + public void addItem(Object stack) {} + + @Override + public void invalidateTooltips(IIngredient unused) { + if (TOOLTIP_CACHE == null) + TOOLTIP_CACHE = MineTweakerHacks.getPrivateStaticObject(IngredientInformation.class, "tooltipCache"); + + if (TOOLTIP_CACHE != null) { + TOOLTIP_CACHE.clear(); + reloadItemList(); + } + } + + private class ReloadHandler implements IEventHandler { + + @Override + public void handle(MineTweakerImplementationAPI.ReloadEvent event) { + if (shouldReloadItemList) { + shouldReloadItemList = false; + ((ItemListOverlay) JEIAddonPlugin.itemListOverlay).rebuildItemFilter(); + } + } + } +} diff --git a/build.gradle b/build.gradle index 0959912..4127ea9 100644 --- a/build.gradle +++ b/build.gradle @@ -71,9 +71,9 @@ task wrapper(type: Wrapper, description: 'Creates and deploys the Gradle wrapper subprojects.each { subproject -> evaluationDependsOn( subproject.path ) } -task setupDecompWorkspaceAll(dependsOn: projects1710.collect { ':' + it + ":setupDecompWorkspace" } + projects18.collect { ':' + it + ':setupDecompWorkspace'} + projects1102.collect { ':' + it + ':setupDecompWorkspace'}) {} +task setupDecompWorkspaceAll(dependsOn: projects1710.collect { ':' + it + ":setupDecompWorkspace" } + projects18.collect { ':' + it + ':setupDecompWorkspace'} + projects1102.collect { ':' + it + ':setupDecompWorkspace'} + projects1112.collect { ':' + it + ':setupDecompWorkspace'}) {} -task setupCIWorkspaceAll(dependsOn: projects1710.collect { ':' + it + ":setupCIWorkspace" } + projects18.collect { ':' + it + ':setupCIWorkspace'} + projects1102.collect { ':' + it + ':setupCIWorkspace'}) {} +task setupCIWorkspaceAll(dependsOn: projects1710.collect { ':' + it + ":setupCIWorkspace" } + projects18.collect { ':' + it + ':setupCIWorkspace'} + projects1102.collect { ':' + it + ':setupCIWorkspace'} + projects1112.collect { ':' + it + ':setupCIWorkspace'}) {} task assembleMC1710(type: Jar, dependsOn: [\ ':ZenScript:build', @@ -117,6 +117,20 @@ task assembleMC1102(type: Jar, dependsOn: [\ } } +task assembleMC1112(type: Jar, dependsOn: [\ + ':ZenScript:build', + ':MineTweaker3-API:build'] + + projects1112.collect { ':' + it + ":build" }) { + archiveName = "CraftTweaker-1.11.2-${mineTweakerVersion}.jar" + + from zipTree(project(":ZenScript").jar.archivePath) + from zipTree(project(':MineTweaker3-API').jar.archivePath) + + for (p in projects1112) { + from zipTree(project(p).jar.archivePath) + } +} + task assembleDevBase1710(type: Jar, dependsOn: [ ':ZenScript:build', ':MineTweaker3-API:build', @@ -150,6 +164,17 @@ task assembleDevBase1102(type: Jar, dependsOn: [ from project(':MineTweaker3-MC1102-Main').sourceSets.main.output } +task assembleDevBase1112(type: Jar, dependsOn: [ + ':ZenScript:build', + ':MineTweaker3-API:build', + ':MineTweaker3-MC1112-Main:build']) { + archiveName = "CraftTweaker-Dev-1.11.2-${mineTweakerVersion}.jar" + + from project(':ZenScript').sourceSets.main.output + from project(':MineTweaker3-API').sourceSets.main.output + from project(':MineTweaker3-MC1112-Main').sourceSets.main.output +} + task assembleDevFull1710(type: Jar, dependsOn: [ ':ZenScript:build', ':MineTweaker3-API:build'] @@ -193,16 +218,33 @@ task assembleDevFull1102(type: Jar, dependsOn: [ } } +task assembleDevFull1112(type: Jar, dependsOn: [ + ':ZenScript:build', + ':MineTweaker3-API:build'] + + projects1112.collect { ':' + it + ":build" }) { + archiveName = "CraftTweaker-Dev-Full-1.11.2-${mineTweakerVersion}.jar" + + from project(':ZenScript').sourceSets.main.output + from project(':MineTweaker3-API').sourceSets.main.output + + for (p in projects1112) { + from project(p).sourceSets.main.output + } +} + task assembleAll(dependsOn: [ assembleMC1710, assembleMC18, assembleMC1102, + assembleMC1112, assembleDevBase1710, assembleDevBase18, assembleDevBase1102, + assembleDevBase1112, assembleDevFull1710, assembleDevFull18, - assembleDevFull1102]) { + assembleDevFull1102, + assembleDevFull1112]) { } configurations { diff --git a/configuration.gradle b/configuration.gradle index 7b75a70..724f29d 100644 --- a/configuration.gradle +++ b/configuration.gradle @@ -51,4 +51,14 @@ ext.projects1102 = [ 'MineTweaker3-MC1102-Main', 'MineTweaker3-MC1102-Mod-JEI', 'MineTweaker3-MC1102-Mod-IC2' +] + +// ####################### +// ### 1.11.2 settings ### +// ####################### + +ext.forgeVersion1112 = "1.11.2-13.20.0.2232" +ext.projects1112 = [ + 'MineTweaker3-MC1112-Main', + 'MineTweaker3-MC1112-Mod-JEI' ] \ No newline at end of file