mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Autocrafter uncluttering and drag drop support
This commit is contained in:
parent
851d6fb0bf
commit
d4e9a5d010
@ -9,11 +9,12 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerAutocrafter extends Container {
|
||||
public class ContainerAutocrafter extends ContainerBase {
|
||||
|
||||
private TileEntityMachineAutocrafter autocrafter;
|
||||
|
||||
public ContainerAutocrafter(InventoryPlayer invPlayer, TileEntityMachineAutocrafter tedf) {
|
||||
super(invPlayer, tedf);
|
||||
autocrafter = tedf;
|
||||
|
||||
/* TEMPLATE */
|
||||
@ -25,25 +26,14 @@ public class ContainerAutocrafter extends Container {
|
||||
this.addSlotToContainer(new SlotPattern(tedf, 9, 116, 40));
|
||||
|
||||
/* RECIPE */
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
this.addSlotToContainer(new Slot(tedf, j + i * 3 + 10, 44 + j * 18, 86 + i * 18));
|
||||
}
|
||||
}
|
||||
addSlots(tedf,10, 44, 86, 3, 3);
|
||||
|
||||
this.addSlotToContainer(new Slot(tedf, 19, 116, 104));
|
||||
|
||||
//Battery
|
||||
this.addSlotToContainer(new Slot(tedf, 20, 17, 99));
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 9; j++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 158 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 216));
|
||||
}
|
||||
playerInv(invPlayer,8,158,216);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,7 +80,7 @@ public class ContainerAutocrafter extends Container {
|
||||
}
|
||||
|
||||
slot.onSlotChanged();
|
||||
autocrafter.initPattern(slot.getStack(), index);
|
||||
autocrafter.matcher.initPatternSmart(autocrafter.getWorldObj(), slot.getStack(), index);
|
||||
autocrafter.updateTemplateGrid();
|
||||
|
||||
return ret;
|
||||
@ -101,9 +91,4 @@ public class ContainerAutocrafter extends Container {
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return autocrafter.isUseableByPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -550,7 +550,6 @@ public class Fluids {
|
||||
//bug meth
|
||||
metaOrder.add(PHEROMONE);
|
||||
metaOrder.add(PHEROMONE_M);
|
||||
metaOrder.add(SLOP);
|
||||
|
||||
//ANY INTERNAL RENAMING MUST BE REFLECTED HERE - DON'T FORGET TO CHANGE: LANG FILES + TYPE'S STRING ID + NAME OF TANK/GUI TEXTURE FILES!
|
||||
// V
|
||||
|
||||
@ -38,14 +38,14 @@ public class GUIAutocrafter extends GuiInfoContainer {
|
||||
for(int i = 0; i < 9; ++i) {
|
||||
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i);
|
||||
|
||||
if(this.isMouseOverSlot(slot, x, y) && diFurnace.modes[i] != null) {
|
||||
if(this.isMouseOverSlot(slot, x, y) && diFurnace.matcher.modes[i] != null) {
|
||||
|
||||
String label = EnumChatFormatting.YELLOW + "";
|
||||
|
||||
switch(diFurnace.modes[i]) {
|
||||
switch(diFurnace.matcher.modes[i]) {
|
||||
case "exact": label += "Item and meta match"; break;
|
||||
case "wildcard": label += "Item matches"; break;
|
||||
default: label += "Ore dict key matches: " + diFurnace.modes[i]; break;
|
||||
default: label += "Ore dict key matches: " + diFurnace.matcher.modes[i]; break;
|
||||
}
|
||||
|
||||
this.func_146283_a(Arrays.asList(new String[] { EnumChatFormatting.RED + "Right click to change", label }), x, y - 30);
|
||||
|
||||
@ -6,6 +6,8 @@ import java.util.List;
|
||||
import com.hbm.inventory.container.ContainerAutocrafter;
|
||||
import com.hbm.inventory.gui.GUIAutocrafter;
|
||||
import com.hbm.lib.Library;
|
||||
import com.hbm.module.ModulePatternMatcher;
|
||||
import com.hbm.tileentity.IFilterable;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.BufferUtil;
|
||||
@ -20,106 +22,34 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityMachineAutocrafter extends TileEntityMachineBase implements IEnergyReceiverMK2, IGUIProvider {
|
||||
public class TileEntityMachineAutocrafter extends TileEntityMachineBase implements IEnergyReceiverMK2, IGUIProvider, IFilterable {
|
||||
|
||||
public static final String MODE_EXACT = "exact";
|
||||
public static final String MODE_WILDCARD = "wildcard";
|
||||
public String[] modes = new String[9];
|
||||
|
||||
public List<IRecipe> recipes = new ArrayList();
|
||||
public int recipeIndex;
|
||||
public int recipeCount;
|
||||
|
||||
public ModulePatternMatcher matcher;
|
||||
|
||||
public TileEntityMachineAutocrafter() {
|
||||
super(21);
|
||||
this.matcher = new ModulePatternMatcher(9);
|
||||
}
|
||||
|
||||
public void initPattern(ItemStack stack, int i) {
|
||||
|
||||
if(worldObj.isRemote) return;
|
||||
|
||||
if(stack == null) {
|
||||
modes[i] = null;
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> names = ItemStackUtil.getOreDictNames(stack);
|
||||
|
||||
if(iterateAndCheck(names, i ,"ingot")) return;
|
||||
if(iterateAndCheck(names, i ,"block")) return;
|
||||
if(iterateAndCheck(names, i ,"dust")) return;
|
||||
if(iterateAndCheck(names, i ,"nugget")) return;
|
||||
if(iterateAndCheck(names, i ,"plate")) return;
|
||||
|
||||
if(stack.getHasSubtypes()) {
|
||||
modes[i] = MODE_EXACT;
|
||||
} else {
|
||||
modes[i] = MODE_WILDCARD;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean iterateAndCheck(List<String> names, int i, String prefix) {
|
||||
|
||||
for(String s : names) {
|
||||
if(s.startsWith(prefix)) {
|
||||
modes[i] = s;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextMode(int i) {
|
||||
|
||||
if(worldObj.isRemote) return;
|
||||
|
||||
ItemStack stack = slots[i];
|
||||
|
||||
if(stack == null) {
|
||||
modes[i] = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if(modes[i] == null) {
|
||||
modes[i] = MODE_EXACT;
|
||||
} else if(MODE_EXACT.equals(modes[i])) {
|
||||
modes[i] = MODE_WILDCARD;
|
||||
} else if(MODE_WILDCARD.equals(modes[i])) {
|
||||
|
||||
List<String> names = ItemStackUtil.getOreDictNames(stack);
|
||||
|
||||
if(names.isEmpty()) {
|
||||
modes[i] = MODE_EXACT;
|
||||
} else {
|
||||
modes[i] = names.get(0);
|
||||
}
|
||||
} else {
|
||||
|
||||
List<String> names = ItemStackUtil.getOreDictNames(stack);
|
||||
|
||||
if(names.size() < 2 || modes[i].equals(names.get(names.size() - 1))) {
|
||||
modes[i] = MODE_EXACT;
|
||||
} else {
|
||||
|
||||
for(int j = 0; j < names.size() - 1; j++) {
|
||||
|
||||
if(modes[i].equals(names.get(j))) {
|
||||
modes[i] = names.get(j + 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.matcher.nextMode(worldObj, slots[i], i);
|
||||
}
|
||||
|
||||
|
||||
public void nextTemplate() {
|
||||
|
||||
if(worldObj.isRemote) return;
|
||||
@ -203,14 +133,7 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
public void serialize(ByteBuf buf) {
|
||||
super.serialize(buf);
|
||||
buf.writeLong(power);
|
||||
for(int i = 0; i < 9; i++) {
|
||||
if(modes[i] != null) {
|
||||
buf.writeBoolean(true);
|
||||
BufferUtil.writeString(buf, modes[i]);
|
||||
} else
|
||||
buf.writeBoolean(false);
|
||||
}
|
||||
|
||||
matcher.serialize(buf);
|
||||
buf.writeInt(recipeCount);
|
||||
buf.writeInt(recipeIndex);
|
||||
}
|
||||
@ -219,12 +142,7 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
public void deserialize(ByteBuf buf) {
|
||||
super.deserialize(buf);
|
||||
power = buf.readLong();
|
||||
|
||||
modes = new String[9];
|
||||
for(int i = 0; i < 9; i++) {
|
||||
if(buf.readBoolean()) modes[i] = BufferUtil.readString(buf);
|
||||
}
|
||||
|
||||
matcher.deserialize(buf);
|
||||
recipeCount = buf.readInt();
|
||||
recipeIndex = buf.readInt();
|
||||
}
|
||||
@ -270,15 +188,10 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
|
||||
if(i > 9 && i < 19) {
|
||||
ItemStack filter = slots[i - 10];
|
||||
String mode = modes[i - 10];
|
||||
|
||||
if(filter == null || mode == null || mode.isEmpty()) return true;
|
||||
|
||||
if(isValidForFilter(filter, mode, stack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
if(filter == null) return true;
|
||||
|
||||
return !matcher.isValidForFilter(filter, i, stack);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -303,11 +216,8 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
List<Integer> validSlots = new ArrayList();
|
||||
for(int i = 0; i < 9; i++) {
|
||||
ItemStack filter = slots[i];
|
||||
String mode = modes[i];
|
||||
|
||||
if(filter == null || mode == null || mode.isEmpty()) continue;
|
||||
|
||||
if(isValidForFilter(filter, mode, stack)) {
|
||||
|
||||
if(matcher.isValidForFilter(filter, i, stack)) {
|
||||
validSlots.add(i + 10);
|
||||
|
||||
//if the current slot is valid and has no item in it, shortcut to true [*]
|
||||
@ -345,17 +255,6 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isValidForFilter(ItemStack filter, String mode, ItemStack input) {
|
||||
|
||||
switch(mode) {
|
||||
case MODE_EXACT: return input.isItemEqual(filter) && ItemStack.areItemStackTagsEqual(input, filter);
|
||||
case MODE_WILDCARD: return input.getItem() == filter.getItem() && ItemStack.areItemStackTagsEqual(input, filter);
|
||||
default:
|
||||
List<String> keys = ItemStackUtil.getOreDictNames(input);
|
||||
return keys.contains(mode);
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryCrafting getTemplateGrid() {
|
||||
this.craftingInventory.loadIventory(slots, 0);
|
||||
return this.craftingInventory;
|
||||
@ -365,7 +264,7 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
this.craftingInventory.loadIventory(slots, 10);
|
||||
return this.craftingInventory;
|
||||
}
|
||||
|
||||
|
||||
public static class InventoryCraftingAuto extends InventoryCrafting {
|
||||
|
||||
public InventoryCraftingAuto(int width, int height) {
|
||||
@ -412,13 +311,7 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
this.power = nbt.getLong("power");
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
if(nbt.hasKey("mode" + i)) {
|
||||
modes[i] = nbt.getString("mode" + i);
|
||||
}
|
||||
}
|
||||
|
||||
matcher.readFromNBT(nbt);
|
||||
this.recipes = getMatchingRecipes(this.getTemplateGrid());
|
||||
this.recipeCount = recipes.size();
|
||||
this.recipeIndex = nbt.getInteger("rec");
|
||||
@ -434,13 +327,7 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setLong("power", power);
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
if(modes[i] != null) {
|
||||
nbt.setString("mode" + i, modes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
matcher.writeToNBT(nbt);
|
||||
nbt.setInteger("rec", this.recipeIndex);
|
||||
}
|
||||
|
||||
@ -454,4 +341,18 @@ public class TileEntityMachineAutocrafter extends TileEntityMachineBase implemen
|
||||
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return new GUIAutocrafter(player.inventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(EntityPlayer player) {
|
||||
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
|
||||
}
|
||||
@Override
|
||||
public void setFilterContents(NBTTagCompound nbt) {
|
||||
int slot = nbt.getInteger("slot");
|
||||
setInventorySlotContents(
|
||||
slot,
|
||||
new ItemStack(Item.getItemById(nbt.getInteger("id")), nbt.getInteger("meta")));
|
||||
nextMode(slot);
|
||||
markChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user