mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-18 11:29:23 +00:00
Move the strange block-scope class SpeciesList which was breaking S2S
See https://github.com/MinecraftForge/Srg2Source/issues/18
This commit is contained in:
1 parent
9e47e018cf
commit
601e20fe99
4 files changed
+338
-320
No files matched your search
@@ -1,318 +0,0 @@
|
||||
package binnie.genetics.machine;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.inventory.ComponentInventory;
|
||||
import binnie.core.machines.inventory.SetList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ComponentIndexerInventory<T> extends ComponentInventory implements IInventory {
|
||||
int indexerSize;
|
||||
public int guiRefreshCounter;
|
||||
List<ItemStack> indexerInventory;
|
||||
public List<Integer> sortedInventory;
|
||||
@Nullable
|
||||
T sortingMode;
|
||||
boolean needsSorting;
|
||||
|
||||
public ComponentIndexerInventory(final Machine machine) {
|
||||
super(machine);
|
||||
this.indexerSize = -1;
|
||||
this.guiRefreshCounter = 0;
|
||||
this.indexerInventory = new SetList<>();
|
||||
this.sortedInventory = new SetList<>();
|
||||
this.needsSorting = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
if (this.indexerSize > 0) {
|
||||
return this.indexerSize + 1;
|
||||
}
|
||||
return this.indexerInventory.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(final int index) {
|
||||
if (index >= 0 && index < this.indexerInventory.size()) {
|
||||
return this.indexerInventory.get(index);
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(final int index, final int amount) {
|
||||
ItemStack stackInSlot = this.getStackInSlot(index);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
final ItemStack returnStack = stackInSlot.copy();
|
||||
this.setInventorySlotContents(index, ItemStack.EMPTY);
|
||||
return returnStack;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
super.markDirty();
|
||||
++this.guiRefreshCounter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(final int index, final ItemStack itemStack) {
|
||||
if (index >= 0 && index < this.indexerInventory.size()) {
|
||||
this.indexerInventory.set(index, itemStack);
|
||||
} else if (!itemStack.isEmpty()) {
|
||||
this.indexerInventory.add(itemStack);
|
||||
}
|
||||
this.needsSorting = true;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ItemStack getStackInSlotOnClosing(final int var1) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getInventoryName() {
|
||||
// return "";
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer(final EntityPlayer var1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void openInventory() {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void closeInventory() {
|
||||
// }
|
||||
|
||||
public void setMode(final T mode) {
|
||||
this.sortingMode = mode;
|
||||
this.needsSorting = true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getMode() {
|
||||
return this.sortingMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(final NBTTagCompound nbttagcompound2) {
|
||||
NBTTagCompound nbttagcompound = super.writeToNBT(nbttagcompound2);
|
||||
final NBTTagList indexerNBT = new NBTTagList();
|
||||
for (final ItemStack item : this.indexerInventory) {
|
||||
final NBTTagCompound itemNBT = new NBTTagCompound();
|
||||
item.writeToNBT(itemNBT);
|
||||
indexerNBT.appendTag(itemNBT);
|
||||
}
|
||||
nbttagcompound.setTag("indexer", indexerNBT);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
final NBTTagList indexerNBT = nbttagcompound.getTagList("indexer", 10);
|
||||
this.indexerInventory.clear();
|
||||
for (int i = 0; i < indexerNBT.tagCount(); ++i) {
|
||||
final NBTTagCompound itemNBT = indexerNBT.getCompoundTagAt(i);
|
||||
this.setInventorySlotContents(i, new ItemStack(itemNBT));
|
||||
}
|
||||
this.needsSorting = true;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public abstract void Sort();
|
||||
|
||||
public static class ComponentApiaristIndexerInventory extends ComponentIndexerInventory<ComponentApiaristIndexerInventory.Mode> implements IInventory {
|
||||
public ComponentApiaristIndexerInventory(final Machine machine) {
|
||||
super(machine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Sort() {
|
||||
int i = 0;
|
||||
while (i < this.indexerInventory.size()) {
|
||||
if (this.indexerInventory.get(i) == null) {
|
||||
this.indexerInventory.remove(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (!this.needsSorting || this.sortingMode == null) {
|
||||
return;
|
||||
}
|
||||
this.needsSorting = false;
|
||||
++this.guiRefreshCounter;
|
||||
switch (this.sortingMode) {
|
||||
case Species:
|
||||
case Type: {
|
||||
class SpeciesList {
|
||||
public List<Integer> drones;
|
||||
public List<Integer> queens;
|
||||
public List<Integer> princesses;
|
||||
public List<ItemStack> bees;
|
||||
|
||||
SpeciesList() {
|
||||
this.drones = new ArrayList<>();
|
||||
this.queens = new ArrayList<>();
|
||||
this.princesses = new ArrayList<>();
|
||||
this.bees = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void add(final ItemStack stack) {
|
||||
this.bees.add(stack);
|
||||
}
|
||||
}
|
||||
final Map<Integer, SpeciesList> speciesList = new HashMap<>();
|
||||
for (final ItemStack itemStack : this.indexerInventory) {
|
||||
final int species = itemStack.getItemDamage();
|
||||
if (!speciesList.containsKey(species)) {
|
||||
speciesList.put(species, new SpeciesList());
|
||||
}
|
||||
speciesList.get(species).add(itemStack);
|
||||
}
|
||||
for (final SpeciesList sortableList : speciesList.values()) {
|
||||
for (final ItemStack beeStack : sortableList.bees) {
|
||||
if (Binnie.GENETICS.getBeeRoot().isDrone(beeStack)) {
|
||||
sortableList.drones.add(this.indexerInventory.indexOf(beeStack));
|
||||
} else if (Binnie.GENETICS.getBeeRoot().isMated(beeStack)) {
|
||||
sortableList.queens.add(this.indexerInventory.indexOf(beeStack));
|
||||
} else {
|
||||
sortableList.princesses.add(this.indexerInventory.indexOf(beeStack));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.sortedInventory = new SetList<>();
|
||||
switch (this.sortingMode) {
|
||||
case Species: {
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).queens);
|
||||
this.sortedInventory.addAll(speciesList.get(j).princesses);
|
||||
this.sortedInventory.addAll(speciesList.get(j).drones);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Type: {
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).queens);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).princesses);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).drones);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
this.sortedInventory.clear();
|
||||
for (i = 0; i < this.indexerInventory.size(); ++i) {
|
||||
this.sortedInventory.add(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TextComponentString(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.sortedInventory.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(final int i, final ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
None,
|
||||
Species,
|
||||
Type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package binnie.genetics.machine.indexer;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.inventory.SetList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ComponentApiaristIndexerInventory extends ComponentIndexerInventory<ComponentApiaristIndexerInventory.Mode> implements IInventory {
|
||||
private static class SpeciesList {
|
||||
public List<Integer> drones;
|
||||
public List<Integer> queens;
|
||||
public List<Integer> princesses;
|
||||
public List<ItemStack> bees;
|
||||
|
||||
SpeciesList() {
|
||||
this.drones = new ArrayList<>();
|
||||
this.queens = new ArrayList<>();
|
||||
this.princesses = new ArrayList<>();
|
||||
this.bees = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void add(final ItemStack stack) {
|
||||
this.bees.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
public ComponentApiaristIndexerInventory(final Machine machine) {
|
||||
super(machine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Sort() {
|
||||
int i = 0;
|
||||
while (i < this.indexerInventory.size()) {
|
||||
if (this.indexerInventory.get(i) == null) {
|
||||
this.indexerInventory.remove(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (!this.needsSorting || this.sortingMode == null) {
|
||||
return;
|
||||
}
|
||||
this.needsSorting = false;
|
||||
++this.guiRefreshCounter;
|
||||
switch (this.sortingMode) {
|
||||
case Species:
|
||||
case Type: {
|
||||
|
||||
final Map<Integer, SpeciesList> speciesList = new HashMap<>();
|
||||
for (final ItemStack itemStack : this.indexerInventory) {
|
||||
final int species = itemStack.getItemDamage();
|
||||
if (!speciesList.containsKey(species)) {
|
||||
speciesList.put(species, new SpeciesList());
|
||||
}
|
||||
speciesList.get(species).add(itemStack);
|
||||
}
|
||||
for (final SpeciesList sortableList : speciesList.values()) {
|
||||
for (final ItemStack beeStack : sortableList.bees) {
|
||||
if (Binnie.GENETICS.getBeeRoot().isDrone(beeStack)) {
|
||||
sortableList.drones.add(this.indexerInventory.indexOf(beeStack));
|
||||
} else if (Binnie.GENETICS.getBeeRoot().isMated(beeStack)) {
|
||||
sortableList.queens.add(this.indexerInventory.indexOf(beeStack));
|
||||
} else {
|
||||
sortableList.princesses.add(this.indexerInventory.indexOf(beeStack));
|
||||
}
|
||||
}
|
||||
}
|
||||
this.sortedInventory = new SetList<>();
|
||||
switch (this.sortingMode) {
|
||||
case Species: {
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).queens);
|
||||
this.sortedInventory.addAll(speciesList.get(j).princesses);
|
||||
this.sortedInventory.addAll(speciesList.get(j).drones);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Type: {
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).queens);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).princesses);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 1024; ++j) {
|
||||
if (speciesList.containsKey(j)) {
|
||||
this.sortedInventory.addAll(speciesList.get(j).drones);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
this.sortedInventory.clear();
|
||||
for (i = 0; i < this.indexerInventory.size(); ++i) {
|
||||
this.sortedInventory.add(i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return new TextComponentString(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.sortedInventory.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(final int i, final ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public enum Mode {
|
||||
None,
|
||||
Species,
|
||||
Type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package binnie.genetics.machine.indexer;
|
||||
|
||||
import binnie.Binnie;
|
||||
import binnie.core.machines.Machine;
|
||||
import binnie.core.machines.inventory.ComponentInventory;
|
||||
import binnie.core.machines.inventory.SetList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ComponentIndexerInventory<T> extends ComponentInventory implements IInventory {
|
||||
int indexerSize;
|
||||
public int guiRefreshCounter;
|
||||
List<ItemStack> indexerInventory;
|
||||
public List<Integer> sortedInventory;
|
||||
@Nullable
|
||||
T sortingMode;
|
||||
boolean needsSorting;
|
||||
|
||||
public ComponentIndexerInventory(final Machine machine) {
|
||||
super(machine);
|
||||
this.indexerSize = -1;
|
||||
this.guiRefreshCounter = 0;
|
||||
this.indexerInventory = new SetList<>();
|
||||
this.sortedInventory = new SetList<>();
|
||||
this.needsSorting = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
if (this.indexerSize > 0) {
|
||||
return this.indexerSize + 1;
|
||||
}
|
||||
return this.indexerInventory.size() + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(final int index) {
|
||||
if (index >= 0 && index < this.indexerInventory.size()) {
|
||||
return this.indexerInventory.get(index);
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(final int index, final int amount) {
|
||||
ItemStack stackInSlot = this.getStackInSlot(index);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
final ItemStack returnStack = stackInSlot.copy();
|
||||
this.setInventorySlotContents(index, ItemStack.EMPTY);
|
||||
return returnStack;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
super.markDirty();
|
||||
++this.guiRefreshCounter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(final int index, final ItemStack itemStack) {
|
||||
if (index >= 0 && index < this.indexerInventory.size()) {
|
||||
this.indexerInventory.set(index, itemStack);
|
||||
} else if (!itemStack.isEmpty()) {
|
||||
this.indexerInventory.add(itemStack);
|
||||
}
|
||||
this.needsSorting = true;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ItemStack getStackInSlotOnClosing(final int var1) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getInventoryName() {
|
||||
// return "";
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer(final EntityPlayer var1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void openInventory() {
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void closeInventory() {
|
||||
// }
|
||||
|
||||
public void setMode(final T mode) {
|
||||
this.sortingMode = mode;
|
||||
this.needsSorting = true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T getMode() {
|
||||
return this.sortingMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(final NBTTagCompound nbttagcompound2) {
|
||||
NBTTagCompound nbttagcompound = super.writeToNBT(nbttagcompound2);
|
||||
final NBTTagList indexerNBT = new NBTTagList();
|
||||
for (final ItemStack item : this.indexerInventory) {
|
||||
final NBTTagCompound itemNBT = new NBTTagCompound();
|
||||
item.writeToNBT(itemNBT);
|
||||
indexerNBT.appendTag(itemNBT);
|
||||
}
|
||||
nbttagcompound.setTag("indexer", indexerNBT);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
final NBTTagList indexerNBT = nbttagcompound.getTagList("indexer", 10);
|
||||
this.indexerInventory.clear();
|
||||
for (int i = 0; i < indexerNBT.tagCount(); ++i) {
|
||||
final NBTTagCompound itemNBT = indexerNBT.getCompoundTagAt(i);
|
||||
this.setInventorySlotContents(i, new ItemStack(itemNBT));
|
||||
}
|
||||
this.needsSorting = true;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public abstract void Sort();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user