mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-11 15:57:34 +00:00
Started with 1.10 and 1.11.2
This commit is contained in:
125 files changed
+4845
-4991
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Object> inputs, Object output) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFurnace(Object object) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFuel(Collection<Object> 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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<Object> inputs, Object output);
|
||||
|
||||
void removeFurnace(Object output);
|
||||
|
||||
void addFuel(Collection<Object> 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);
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<Integer> idrange = new ArrayList<Integer>();
|
||||
List<Integer> idrange = new ArrayList<>();
|
||||
idrange.add(1);
|
||||
idrange.add(2);
|
||||
GuiRegistry.registerGui(idrange, new GuiHandlerVanilla());
|
||||
|
||||
@@ -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<GuiButton> incompatible) {
|
||||
this.incompatible = incompatible;
|
||||
}
|
||||
|
||||
public List<GuiButton> getIncompatible() {
|
||||
return incompatible;
|
||||
}
|
||||
|
||||
public void setIncompatible(List<GuiButton> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-20
@@ -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<ItemStack> list = new ArrayList();
|
||||
ArrayList<ItemStack> 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<ItemStack> list = new ArrayList();
|
||||
if(parent.selectedSlot.getStack().getItem().getHasSubtypes()) {
|
||||
ArrayList<ItemStack> 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<ItemStack> list = new ArrayList();
|
||||
ArrayList<ItemStack> 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<ItemStack> list = new ArrayList();
|
||||
if(parent.selectedSlot.getStack().getItem().getHasSubtypes()) {
|
||||
ArrayList<ItemStack> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+32
-24
@@ -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<SlotRecipe> recipeSlots = new LinkedList<SlotRecipe>();
|
||||
protected List<SlotRecipe> 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<SlotRecipe> getRecipeSlots() {
|
||||
return recipeSlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Slot addSlotToContainer(Slot slotIn) {
|
||||
if(slotIn instanceof SlotRecipe) {
|
||||
getRecipeSlots().add((SlotRecipe) slotIn);
|
||||
}
|
||||
return super.addSlotToContainer(slotIn);
|
||||
}
|
||||
}
|
||||
@@ -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<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
||||
for (Slider slider : but.getValue()) {
|
||||
for(Pair<CheckButtonRecipe, Slider[]> 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<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
||||
for (Slider slider : but.getValue()) {
|
||||
for(Pair<CheckButtonRecipe, Slider[]> 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<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
||||
for (Slider slider : but.getValue()) {
|
||||
for(Pair<CheckButtonRecipe, Slider[]> 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<CheckButtonRecipe, Slider[]> but : menu.getButtons()) {
|
||||
for (Slider slider : but.getValue()) {
|
||||
for(Pair<CheckButtonRecipe, Slider[]> 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<String> lines = new LinkedList<String>();
|
||||
List<String> 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<String> lines = new LinkedList<String>();
|
||||
List<String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<List<Integer>, IGuiHandler> guiMap = new HashMap<List<Integer>, IGuiHandler>();
|
||||
public static Map<List<Integer>, IGuiHandler> guiMap = new HashMap<>();
|
||||
|
||||
public static void registerGui(List<Integer> idRange, IGuiHandler handler) {
|
||||
getGuiMap().put(idRange, handler);
|
||||
}
|
||||
|
||||
public static IGuiHandler getHandlerForID(int id) {
|
||||
for (Map.Entry<List<Integer>, IGuiHandler> entry : getGuiMap().entrySet()) {
|
||||
if (entry.getKey().contains(id)) {
|
||||
for(Map.Entry<List<Integer>, IGuiHandler> entry : getGuiMap().entrySet()) {
|
||||
if(entry.getKey().contains(id)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<String, Boolean> propertyMap = new HashMap<String, Boolean>();
|
||||
private Map<String, Integer> properties = new HashMap<String, Integer>();
|
||||
private Map<String, Boolean> propertyMap = new HashMap<>();
|
||||
private Map<String, Integer> 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
+4
-6
@@ -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:
|
||||
|
||||
+6
-7
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+84
-107
@@ -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<Pair<CheckButtonRecipe, Slider[]>> buttons = new ArrayList<Pair<CheckButtonRecipe, Slider[]>>();
|
||||
|
||||
// public Pair<CheckButtonRecipe, Slider[]> matchNotEmpty;
|
||||
public Pair<CheckButtonRecipe, Slider[]> useOreDict;
|
||||
public Pair<CheckButtonRecipe, Slider[]> matchAnyMetadata;
|
||||
public Pair<CheckButtonRecipe, Slider[]> anyDamage;
|
||||
public Pair<CheckButtonRecipe, Slider[]> onlyDamage;
|
||||
|
||||
// public Pair<CheckButtonRecipe, Slider[]> damage;
|
||||
public Pair<CheckButtonRecipe, Slider[]> greaterThanEqualDamage;
|
||||
public Pair<CheckButtonRecipe, Slider[]> lessThanDamage;
|
||||
public Pair<CheckButtonRecipe, Slider[]> betweenDamage;
|
||||
|
||||
public Pair<CheckButtonRecipe, Slider[]> nbt;
|
||||
|
||||
// public Pair<CheckButtonRecipe, Slider[]> transformDamage;
|
||||
// public Pair<CheckButtonRecipe, Slider[]> transformReplace;
|
||||
// public Pair<CheckButtonRecipe, Slider[]> transformReplace;
|
||||
public Pair<CheckButtonRecipe, Slider[]> reuse;
|
||||
public Pair<CheckButtonRecipe, Slider[]> noReturn;
|
||||
// public Pair<CheckButtonRecipe, Slider[]> giveBack;
|
||||
|
||||
|
||||
private GuiBase parent;
|
||||
private int x;
|
||||
private int y;
|
||||
private List<Pair<CheckButtonRecipe, Slider[]>> buttons = new ArrayList<>();
|
||||
// public Pair<CheckButtonRecipe, Slider[]> 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<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 1, x, y + (15 * buttonCount++), "Ore Dictionary", false, "oreDictionary"), new Slider[]{});
|
||||
matchAnyMetadata = new MutablePair<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 2, x, y + (15 * buttonCount++), "Any Metadata", false, "anyMetadata"), new Slider[]{});
|
||||
anyDamage = new MutablePair<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 3, x, y + (15 * buttonCount++), "Any Damage", false, "anyDamage"), new Slider[]{});
|
||||
onlyDamage = new MutablePair<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 4, x, y + (15 * buttonCount++), "Only Damage", false, "onlyDamage"), new Slider[]{});
|
||||
greaterThanEqualDamage = new MutablePair<CheckButtonRecipe, Slider[]>(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<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 7, x, y + (15 * buttonCount++), "Damage<X", false, "ltd"), new Slider[]{new Slider("ltd", 11, 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());
|
||||
}
|
||||
lessThanDamage = new MutablePair<>(new CheckButtonRecipe(parent, 7, x, y + (15 * buttonCount++), "Damage<X", false, "ltd"), new Slider[]{new Slider("ltd", 11, 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());
|
||||
}
|
||||
})});
|
||||
betweenDamage = new MutablePair<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "X<Damage<Y", false, "betweenDamage"), new Slider[]{new Slider("betweenDamageX", 12, 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());
|
||||
}
|
||||
betweenDamage = new MutablePair<>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "X<Damage<Y", false, "betweenDamage"), new Slider[]{new Slider("betweenDamageX", 12, 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());
|
||||
}
|
||||
}), 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<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "NBT", false, "nbt"), new Slider[]{});
|
||||
|
||||
reuse = new MutablePair<CheckButtonRecipe, Slider[]>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Reuse", false, "reuse"), new Slider[]{});
|
||||
noReturn = new MutablePair<CheckButtonRecipe, Slider[]>(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<CheckButtonRecipe, Slider[]> but : this.buttons) {
|
||||
|
||||
for(Pair<CheckButtonRecipe, Slider[]> but : this.buttons) {
|
||||
parent.getButtonList().add(but.getLeft());
|
||||
}
|
||||
|
||||
useOreDict.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft(), nbt.getLeft()}));
|
||||
matchAnyMetadata.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{useOreDict.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
||||
anyDamage.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
||||
onlyDamage.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
||||
|
||||
greaterThanEqualDamage.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()}));
|
||||
lessThanDamage.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), betweenDamage.getLeft()}));
|
||||
betweenDamage.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft()}));
|
||||
|
||||
nbt.getLeft().setIncompatible(Arrays.<GuiButton>asList(new CheckButtonRecipe[]{useOreDict.getLeft()}));
|
||||
noReturn.getLeft().setIncompatible(Arrays.<GuiButton>asList(reuse.getLeft()));
|
||||
reuse.getLeft().setIncompatible(Arrays.<GuiButton>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<String, Boolean> propertyMap, Map<String, Integer> 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<String, Boolean> propertyMap, String key) {
|
||||
if (propertyMap.containsKey(key)) {
|
||||
if(propertyMap.containsKey(key)) {
|
||||
return propertyMap.get(key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Object getProperty(Map<String, Integer> 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<CheckButtonRecipe, Slider[]> pair : this.buttons) {
|
||||
if (pair.getLeft().getPropertyKey().equals(check.getPropertyKey())) {
|
||||
for(Pair<CheckButtonRecipe, Slider[]> pair : this.buttons) {
|
||||
if(pair.getLeft().getPropertyKey().equals(check.getPropertyKey())) {
|
||||
return pair.getValue();
|
||||
}
|
||||
}
|
||||
return new Slider[0];
|
||||
}
|
||||
|
||||
|
||||
public List<Pair<CheckButtonRecipe, Slider[]>> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
+7
-19
@@ -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);
|
||||
}
|
||||
}
|
||||
+28
-38
@@ -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.<GuiButton>asList(shapeless));
|
||||
shapeless.setIncompatible(Arrays.<GuiButton>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
|
||||
|
||||
+6
-16
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-4
@@ -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;
|
||||
}
|
||||
|
||||
+6
-8
@@ -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 <id>";
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
@Override
|
||||
public EntityPlayer getPlayer() {
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
return Minecraft.getMinecraft().player;
|
||||
}
|
||||
|
||||
}
|
||||
+483
-471
@@ -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<Block, MCBlockDefinition> blockDefinitions = new HashMap<Block, MCBlockDefinition>();
|
||||
public static final IBiome[] biomes;
|
||||
|
||||
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<IItemStack> 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<IItemStack> 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<IItemStack> 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<ItemStack> 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<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
|
||||
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<Block, MCBlockDefinition> blockDefinitions = new HashMap<>();
|
||||
private static final HashMap<List, IOreDictEntry> oreDictArrays = new HashMap<List, IOreDictEntry>();
|
||||
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<IItemStack> 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<IItemStack> 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<IItemStack> 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<ItemStack> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<EntityItem> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Class> apiClasses = new ArrayList<Class>();
|
||||
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<Class> 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<IItemStack> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<Class> classes){
|
||||
public class MineTweakerRegistry {
|
||||
|
||||
public static void getClasses(List<Class> classes) {
|
||||
// method stub, actual content is generated by build process
|
||||
}
|
||||
}
|
||||
+28
-35
@@ -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;
|
||||
}
|
||||
}
|
||||
+9
-15
@@ -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;
|
||||
}
|
||||
}
|
||||
+18
-24
@@ -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;
|
||||
}
|
||||
}
|
||||
+43
-47
@@ -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;
|
||||
}
|
||||
}
|
||||
+6
-11
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<IBlock> getBlocks(){
|
||||
return Collections.<IBlock>singletonList(this);
|
||||
public List<IBlock> 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);
|
||||
}
|
||||
}
|
||||
+15
-24
@@ -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<IBlock> getBlocks(){
|
||||
return Collections.<IBlock>singletonList(this);
|
||||
public List<IBlock> 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 "<block:" + getBlockId(block) + ":" + (meta == OreDictionary.WILDCARD_VALUE ? '*' : meta) + ">";
|
||||
}
|
||||
}
|
||||
@@ -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<IBlock> getBlocks(){
|
||||
return Collections.<IBlock>singletonList(this);
|
||||
public List<IBlock> 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);
|
||||
}
|
||||
}
|
||||
+77
@@ -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<String, IEntityDefinition> 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<Token> 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<Token> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
+52
-45
@@ -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<String, Item> itemNames = new HashMap<String, Item>();
|
||||
public class ItemBracketHandler implements IBracketHandler {
|
||||
|
||||
private static final Map<String, Item> itemNames = new HashMap<>();
|
||||
private static final Map<String, Block> 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<String, Item> getItemNames() {
|
||||
return itemNames;
|
||||
}
|
||||
|
||||
public static Map<String, Block> getBlockNames() {
|
||||
return blockNames;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void rebuildItemRegistry(){
|
||||
public static void rebuildItemRegistry() {
|
||||
itemNames.clear();
|
||||
|
||||
for(ResourceLocation itemName : (Set<ResourceLocation>) 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<Token> tokens){
|
||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> 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<Token> tokens, int startIndex, int endIndex, int meta){
|
||||
|
||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> 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));
|
||||
}
|
||||
}
|
||||
|
||||
+22
-26
@@ -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<String, Fluid> fluidNames = new HashMap<String, Fluid>();
|
||||
public class LiquidBracketHandler implements IBracketHandler {
|
||||
|
||||
private static final Map<String, Fluid> 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<Token> tokens){
|
||||
if(tokens.size() > 2){
|
||||
if(tokens.get(0).getValue().equals("liquid") && tokens.get(1).getValue().equals(":")){
|
||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> 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<Token> tokens, int startIndex, int endIndex){
|
||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> 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));
|
||||
|
||||
+20
-28
@@ -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<IOreDictEntry> getOreList(String wildcardName){
|
||||
List<IOreDictEntry> result = new ArrayList<IOreDictEntry>();
|
||||
public static List<IOreDictEntry> getOreList(String wildcardName) {
|
||||
List<IOreDictEntry> 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<Token> tokens){
|
||||
if(tokens.size() > 2){
|
||||
if(tokens.get(0).getValue().equals("ore") && tokens.get(1).getValue().equals(":")){
|
||||
public IZenSymbol resolve(IEnvironmentGlobal environment, List<Token> 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<Token> tokens, int startIndex, int endIndex){
|
||||
private IZenSymbol find(IEnvironmentGlobal environment, List<Token> 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));
|
||||
|
||||
+38
-50
@@ -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<IBrewingRecipe> getAll() {
|
||||
List<IBrewingRecipe> ret = new ArrayList<IBrewingRecipe>();
|
||||
for (net.minecraftforge.common.brewing.IBrewingRecipe rec : BrewingRecipeRegistry.getRecipes()) {
|
||||
if (rec instanceof net.minecraftforge.common.brewing.AbstractBrewingRecipe) {
|
||||
List<IBrewingRecipe> 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<ItemStack, ItemStack> smeltingList = FurnaceRecipes.instance().getSmeltingList();
|
||||
//
|
||||
// List<ItemStack> toRemove = new ArrayList<ItemStack>();
|
||||
// List<ItemStack> toRemoveValues = new ArrayList<ItemStack>();
|
||||
// for (Map.Entry<ItemStack, ItemStack> 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<ItemStack, ItemStack> smeltingList = FurnaceRecipes.instance().getSmeltingList();
|
||||
//
|
||||
// List<ItemStack> toRemove = new ArrayList<ItemStack>();
|
||||
// List<ItemStack> toRemoveValues = new ArrayList<ItemStack>();
|
||||
// for (Map.Entry<ItemStack, ItemStack> 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<ItemStack> ingredients) {
|
||||
IngredientOr ing;
|
||||
List<IngredientItem> stacks = new ArrayList<IngredientItem>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<NBTBase>{
|
||||
public class NBTConverter implements IDataConverter<NBTBase> {
|
||||
|
||||
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<NBTBase>{
|
||||
return new DataByteArray(((NBTTagByteArray) nbt).getByteArray(), immutable);
|
||||
case 8: // string
|
||||
return new DataString(((NBTTagString) nbt).getString());
|
||||
case 9:{ // list
|
||||
List<IData> values = new ArrayList<IData>();
|
||||
case 9: { // list
|
||||
List<IData> values = new ArrayList<>();
|
||||
List<NBTBase> 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<String, IData> values = new HashMap<String, IData>();
|
||||
case 10: { // compound
|
||||
Map<String, IData> values = new HashMap<>();
|
||||
NBTTagCompound original = (NBTTagCompound) nbt;
|
||||
for(String key : (Set<String>) 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<NBTBase>{
|
||||
}
|
||||
}
|
||||
|
||||
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<IData> values){
|
||||
public NBTBase fromList(List<IData> values) {
|
||||
NBTTagList result = new NBTTagList();
|
||||
for(IData value : values){
|
||||
for(IData value : values) {
|
||||
result.appendTag(from(value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromMap(Map<String, IData> values){
|
||||
public NBTBase fromMap(Map<String, IData> values) {
|
||||
NBTTagCompound result = new NBTTagCompound();
|
||||
for(Map.Entry<String, IData> entry : values.entrySet()){
|
||||
for(Map.Entry<String, IData> 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);
|
||||
}
|
||||
}
|
||||
@@ -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<NBTBase>{
|
||||
public class NBTUpdater extends NBTConverter implements IDataConverter<NBTBase> {
|
||||
|
||||
private final NBTTagCompound nbt;
|
||||
|
||||
public NBTUpdater(NBTTagCompound compound){
|
||||
public NBTUpdater(NBTTagCompound compound) {
|
||||
this.nbt = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTBase fromMap(Map<String, IData> map){
|
||||
for(Map.Entry<String, IData> entry : map.entrySet()){
|
||||
if(nbt.hasKey(entry.getKey())){
|
||||
if(entry.getValue() == null){
|
||||
public NBTBase fromMap(Map<String, IData> map) {
|
||||
for(Map.Entry<String, IData> 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()));
|
||||
}
|
||||
}
|
||||
|
||||
+51
-15
@@ -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<? extends Entity> entityClass;
|
||||
private final String entityName;
|
||||
|
||||
private final Map<IItemStack, IntRange> dropsToAdd = new HashMap<>();
|
||||
private final Map<IItemStack, IntRange> dropsToAddPlayerOnly = new HashMap<>();
|
||||
private final List<IItemStack> dropsToRemove = new ArrayList<>();
|
||||
|
||||
public MCEntityDefinition(Class<? extends Entity> 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<IItemStack, IntRange> getDropsToAdd() {
|
||||
return dropsToAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<IItemStack, IntRange> getDropsToAddPlayerOnly() {
|
||||
return dropsToAddPlayerOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemStack> getDropsToRemove() {
|
||||
return dropsToRemove;
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -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);
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -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);
|
||||
}
|
||||
}
|
||||
+12
-17
@@ -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);
|
||||
|
||||
+2
-7
@@ -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);
|
||||
|
||||
+24
-31
@@ -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);
|
||||
}
|
||||
}
|
||||
+37
-43
@@ -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<Item, List<SetFuelPattern>> quickList = new HashMap<Item, List<SetFuelPattern>>();
|
||||
private final HashMap<Item, List<SetFuelPattern>> quickList = new HashMap<>();
|
||||
private List<IFuelHandler> original;
|
||||
|
||||
private FuelTweaker(){
|
||||
|
||||
private FuelTweaker() {
|
||||
}
|
||||
|
||||
public void register(){
|
||||
try{
|
||||
|
||||
public void register() {
|
||||
try {
|
||||
Field fuelHandlers = GameRegistry.class.getDeclaredField("fuelHandlers");
|
||||
fuelHandlers.setAccessible(true);
|
||||
original = (List<IFuelHandler>) fuelHandlers.get(null);
|
||||
List<IFuelHandler> modified = new ArrayList<IFuelHandler>();
|
||||
List<IFuelHandler> 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<IItemStack> 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<SetFuelPattern>());
|
||||
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;
|
||||
|
||||
+105
-101
@@ -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<ItemStack, ItemStack> smeltingList = FurnaceRecipes.instance().getSmeltingList();
|
||||
|
||||
List<ItemStack> toRemove = new ArrayList<ItemStack>();
|
||||
List<ItemStack> toRemoveValues = new ArrayList<ItemStack>();
|
||||
for(Map.Entry<ItemStack, ItemStack> 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<ItemStack> toRemove = new ArrayList<>();
|
||||
List<ItemStack> toRemoveValues = new ArrayList<>();
|
||||
|
||||
if(input == null) {
|
||||
for(Map.Entry<ItemStack, ItemStack> entry : smeltingList.entrySet()) {
|
||||
if(output.matches(getIItemStack(entry.getValue()))) {
|
||||
toRemove.add(entry.getKey());
|
||||
toRemoveValues.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(Map.Entry<ItemStack, ItemStack> 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<IItemStack> 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<IFurnaceRecipe> getAll() {
|
||||
List<IFurnaceRecipe> retList = new ArrayList<IFurnaceRecipe>();
|
||||
for(Map.Entry<ItemStack, ItemStack> 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<ItemStack> items;
|
||||
private final List<ItemStack> values;
|
||||
|
||||
public RemoveAction(List<ItemStack> items, List<ItemStack> values){
|
||||
|
||||
public RemoveAction(List<ItemStack> items, List<ItemStack> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String, String> TRANSLATIONS = MineTweakerHacks.getTranslations();
|
||||
private static final List<IEntityDefinition> ENTITY_DEFINITIONS = new ArrayList<>();
|
||||
private boolean locked = false;
|
||||
|
||||
private MCGame(){
|
||||
private MCGame() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IItemDefinition> getItems(){
|
||||
List<IItemDefinition> result = new ArrayList<IItemDefinition>();
|
||||
for(ResourceLocation item : (Set<ResourceLocation>) Item.REGISTRY.getKeys()){
|
||||
result.add(new MCItemDefinition(item.toString(), Item.REGISTRY.getObject(item)));
|
||||
}
|
||||
return result;
|
||||
public List<IItemDefinition> getItems() {
|
||||
return Item.REGISTRY.getKeys().stream().map(item -> new MCItemDefinition(item.toString(), Item.REGISTRY.getObject(item))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBlockDefinition> getBlocks(){
|
||||
List<IBlockDefinition> result = new ArrayList<IBlockDefinition>();
|
||||
for(ResourceLocation block : (Set<ResourceLocation>) Block.REGISTRY.getKeys()){
|
||||
result.add(MineTweakerMC.getBlockDefinition(Block.REGISTRY.getObject(block)));
|
||||
}
|
||||
|
||||
return result;
|
||||
public List<IBlockDefinition> getBlocks() {
|
||||
return Block.REGISTRY.getKeys().stream().map(block -> MineTweakerMC.getBlockDefinition(Block.REGISTRY.getObject(block))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidDefinition> getLiquids(){
|
||||
List<ILiquidDefinition> result = new ArrayList<ILiquidDefinition>();
|
||||
for(Map.Entry<String, Fluid> entry : FluidRegistry.getRegisteredFluids().entrySet()){
|
||||
result.add(new MCLiquidDefinition(entry.getValue()));
|
||||
}
|
||||
return result;
|
||||
public List<ILiquidDefinition> getLiquids() {
|
||||
return FluidRegistry.getRegisteredFluids().entrySet().stream().map(entry -> new MCLiquidDefinition(entry.getValue())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBiome> getBiomes(){
|
||||
List<IBiome> result = new ArrayList<IBiome>();
|
||||
for(IBiome biome : MineTweakerMC.biomes){
|
||||
if(biome != null){
|
||||
public List<IBiome> getBiomes() {
|
||||
List<IBiome> 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<IEntityDefinition> getEntities(){
|
||||
List<IEntityDefinition> result = new ArrayList<IEntityDefinition>();
|
||||
|
||||
for(EntityRegistry.EntityRegistration entityRegistration : MineTweakerHacks.getEntityClassRegistrations().values()){
|
||||
result.add(new MCEntityDefinition(entityRegistration));
|
||||
public List<IEntityDefinition> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-26
@@ -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<IOreDictEntry> getOres(){
|
||||
List<IOreDictEntry> result = new ArrayList<IOreDictEntry>();
|
||||
public List<IOreDictEntry> getOres() {
|
||||
List<IOreDictEntry> 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;
|
||||
|
||||
@@ -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<IItemStack> 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.<IItemStack>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.<IItemStack>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.<IItemStack>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<IItemStack> getItems(){
|
||||
public List<IItemStack> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids(){
|
||||
public List<ILiquidStack> 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<IItemStack> 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<IOreDictEntry> getOres(){
|
||||
List<IOreDictEntry> result = new ArrayList<IOreDictEntry>();
|
||||
|
||||
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<IOreDictEntry> getOres() {
|
||||
List<IOreDictEntry> 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+81
-85
@@ -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<IItemStack> getContainers(){
|
||||
List<IItemStack> result = new ArrayList<IItemStack>();
|
||||
for(FluidContainerRegistry.FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()){
|
||||
if(data.fluid.getFluid() == fluid){
|
||||
public List<IItemStack> getContainers() {
|
||||
List<IItemStack> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+36
-43
@@ -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<IItemStack> getItems(){
|
||||
public List<IItemStack> getItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ILiquidStack> getLiquids(){
|
||||
return Collections.<ILiquidStack>singletonList(this);
|
||||
public List<ILiquidStack> 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;
|
||||
}
|
||||
}
|
||||
@@ -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("");
|
||||
}
|
||||
}
|
||||
@@ -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<IMod> iterator(){
|
||||
public Iterator<IMod> iterator() {
|
||||
List<ModContainer> mods = Loader.instance().getActiveModList();
|
||||
return new MappingIterator<ModContainer, IMod>(mods.iterator()){
|
||||
return new MappingIterator<ModContainer, IMod>(mods.iterator()) {
|
||||
@Override
|
||||
public IMod map(ModContainer value){
|
||||
public IMod map(ModContainer value) {
|
||||
return new MCMod(value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+12
-16
@@ -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<MineTweakerCopyClipboardPacket, IMessage>{
|
||||
public class MineTweakerCopyClipboardHandler implements IMessageHandler<MineTweakerCopyClipboardPacket, IMessage> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -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());
|
||||
}
|
||||
}
|
||||
+13
-17
@@ -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<MineTweakerLoadScriptsPacket, IMessage>{
|
||||
public class MineTweakerLoadScriptsHandler implements IMessageHandler<MineTweakerLoadScriptsPacket, IMessage> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
+12
-17
@@ -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);
|
||||
}
|
||||
|
||||
+19
-24
@@ -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<MineTweakerOpenBrowserPacket, IMessage>{
|
||||
@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<MineTweakerOpenBrowserPacket, IMessage> {
|
||||
|
||||
@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");
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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<IOreDictEntry> getEntries(){
|
||||
List<IOreDictEntry> entries = new ArrayList<IOreDictEntry>();
|
||||
for(String key : OreDictionary.getOreNames()){
|
||||
if(!OreDictionary.getOres(key).isEmpty()){
|
||||
public List<IOreDictEntry> getEntries() {
|
||||
List<IOreDictEntry> entries = new ArrayList<>();
|
||||
for(String key : OreDictionary.getOreNames()) {
|
||||
if(!OreDictionary.getOres(key).isEmpty()) {
|
||||
entries.add(MineTweakerMC.getOreDict(key));
|
||||
}
|
||||
}
|
||||
|
||||
+30
-41
@@ -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<IItemStack> getItems() {
|
||||
List<IItemStack> result = new ArrayList<IItemStack>();
|
||||
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<IItemStack> 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);
|
||||
}
|
||||
}
|
||||
|
||||
+43
-30
@@ -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) {
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
+53
-60
@@ -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<MCCraftingInventory> cache = new ThreadLocal<MCCraftingInventory>();
|
||||
private static final ThreadLocal<MCCraftingInventory> cache2 = new ThreadLocal<MCCraftingInventory>();
|
||||
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<Slot> 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();
|
||||
}
|
||||
}
|
||||
+78
-67
@@ -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<IRecipe> recipes;
|
||||
private final List<ICraftingRecipe> transformerRecipes;
|
||||
|
||||
public MCRecipeManager() {
|
||||
recipes = CraftingManager.getInstance().getRecipeList();
|
||||
transformerRecipes = new ArrayList<ICraftingRecipe>();
|
||||
transformerRecipes = new ArrayList<>();
|
||||
}
|
||||
|
||||
private static boolean matches(Object input, IIngredient ingredient) {
|
||||
@@ -70,21 +63,19 @@ public class MCRecipeManager implements IRecipeManager {
|
||||
|
||||
@Override
|
||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient) {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
List<ICraftingRecipe> 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<ICraftingRecipe> getAll() {
|
||||
List<ICraftingRecipe> results = new ArrayList<ICraftingRecipe>();
|
||||
List<ICraftingRecipe> 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<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
List<IRecipe> toRemove = new ArrayList<>();
|
||||
List<Integer> 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<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
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<IRecipe> toRemove = new ArrayList<IRecipe>();
|
||||
List<Integer> removeIndex = new ArrayList<Integer>();
|
||||
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<Object> 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<Integer> removingIndices;
|
||||
private final List<IRecipe> 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
|
||||
|
||||
+47
-59
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -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;
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -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;
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -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;
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -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;
|
||||
}
|
||||
}
|
||||
+15
-12
@@ -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;
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String> 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<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
|
||||
public List<String> 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
|
||||
|
||||
+44
-37
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
+66
-113
@@ -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<? extends WeightedRandom.Item> 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<? extends WeightedRandom.Item> forgeSeedEntry = null;
|
||||
try{
|
||||
try {
|
||||
forgeSeedEntry = (Class<? extends WeightedRandom.Item>) Class.forName("net.minecraftforge.common.ForgeHooks$SeedEntry");
|
||||
}catch(ClassNotFoundException ex){
|
||||
} catch(ClassNotFoundException ex) {
|
||||
}
|
||||
|
||||
SEEDENTRY_SEED = getField(forgeSeedEntry, "seed");
|
||||
|
||||
Constructor<? extends WeightedRandom.Item> 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<Class<? extends Entity>, EntityRegistry.EntityRegistration> getEntityClassRegistrations(){
|
||||
try{
|
||||
return (BiMap<Class<? extends Entity>, EntityRegistry.EntityRegistration>) ENTITYREGISTRY_CLASSREGISTRATIONS.get(EntityRegistry.instance());
|
||||
}catch(IllegalArgumentException ex){
|
||||
|
||||
public static List<NBTBase> getTagList(NBTTagList list) {
|
||||
if(NBTTAGLIST_TAGLIST == null) {
|
||||
return null;
|
||||
}catch(IllegalAccessException ex){
|
||||
}
|
||||
try {
|
||||
return (List<NBTBase>) NBTTAGLIST_TAGLIST.get(list);
|
||||
} catch(IllegalArgumentException ex) {
|
||||
return null;
|
||||
} catch(IllegalAccessException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<NBTBase> 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<String, String> getTranslations() {
|
||||
return getPrivateObject(getPrivateStaticObject(I18n.class, "localizedName", "field_74839_a"), "languageList", "field_74816_c");
|
||||
}
|
||||
|
||||
public static List<ArrayList<ItemStack>> getOreIdStacks(){
|
||||
try{
|
||||
public static List<ArrayList<ItemStack>> getOreIdStacks() {
|
||||
try {
|
||||
return (List<ArrayList<ItemStack>>) OREDICTIONARY_IDTOSTACK.get(null);
|
||||
}catch(IllegalAccessException ex){
|
||||
} catch(IllegalAccessException ex) {
|
||||
MineTweakerAPI.logError("ERROR - could not load ore dictionary stacks!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<List<ItemStack>> getOreIdStacksUn(){
|
||||
try{
|
||||
public static List<List<ItemStack>> getOreIdStacksUn() {
|
||||
try {
|
||||
return (List<List<ItemStack>>) 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> T getPrivateStaticObject(Class<?> cls, String... names){
|
||||
for(String name : names){
|
||||
try{
|
||||
public static <T> 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> T getPrivateObject(Object object, String... names){
|
||||
public static <T> 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) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-9
@@ -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() {
|
||||
}
|
||||
}
|
||||
+10
-15
@@ -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<? extends EntityLivingBase> getLivingEntityClass(String entityClassName){
|
||||
try{
|
||||
public static Class<? extends EntityLivingBase> 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<? extends EntityLivingBase>) 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;
|
||||
}
|
||||
}
|
||||
+33
-45
@@ -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<WeightedItemStack> getSeeds(){
|
||||
public List<WeightedItemStack> getSeeds() {
|
||||
List<? extends WeightedRandom.Item> entries = (List<? extends WeightedRandom.Item>) SEEDS;
|
||||
|
||||
List<WeightedItemStack> results = new ArrayList<WeightedItemStack>();
|
||||
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<Object> removed;
|
||||
|
||||
public RemoveSeedAction(IIngredient ingredient){
|
||||
public RemoveSeedAction(IIngredient ingredient) {
|
||||
this.pattern = ingredient;
|
||||
removed = new ArrayList<Object>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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": []
|
||||
}
|
||||
]
|
||||
@@ -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)
|
||||
+72
-80
@@ -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<Token> 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<Token> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
+133
-130
@@ -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.
|
||||
*
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
-53
@@ -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<ItemStack> getInputs() {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
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<ItemStack> 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)));
|
||||
}
|
||||
}
|
||||
+9
-24
@@ -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)));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+216
-222
@@ -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<Crop> getAllCrops() {
|
||||
Collection<CropCard> ccList = Crops.instance.getCrops();
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return "Registering crop " + c.getName();
|
||||
}
|
||||
List<Crop> 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<Crop> getAllCrops() {
|
||||
Collection<CropCard> ccList = Crops.instance.getCrops();
|
||||
|
||||
List<Crop> cList = new ArrayList<Crop>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 125 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user