Added Oredict-based checking to everything with filters~

This commit is contained in:
Ellpeck 2016-07-24 18:58:08 +02:00
parent 5e63208098
commit 38de0e9ac7
13 changed files with 109 additions and 37 deletions

View file

@ -33,6 +33,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.stats.Achievement;
import net.minecraft.util.text.TextFormatting;
import org.apache.commons.lang3.ArrayUtils;
import java.awt.*;
import java.net.URI;
@ -309,7 +310,7 @@ public final class BookletUtils{
* Called when one of the buttons to open an index or a chapter is pressed
*/
public static void handleChapterButtonClick(GuiBooklet booklet, GuiButton button){
int place = Util.arrayContains(booklet.chapterButtons, button);
int place = ArrayUtils.indexOf(booklet.chapterButtons, button);
if(place >= 0){
if(booklet.currentEntrySet.getCurrentEntry() != null){
if(booklet.currentEntrySet.getCurrentChapter() == null){

View file

@ -18,6 +18,7 @@ import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import org.apache.commons.lang3.ArrayUtils;
import java.util.HashMap;
import java.util.Map;
@ -34,7 +35,7 @@ public class BookletPageAA extends BookletPage{
@Override
public int getID(){
return Util.arrayContains(this.chapter.getPages(), this)+1;
return ArrayUtils.indexOf(this.chapter.getPages(), this)+1;
}
@Override

View file

@ -34,7 +34,7 @@ public class WorldData{
public static final String DATA_TAG = ModUtil.MOD_ID+"data";
public static final ArrayList<PlayerSave> PLAYER_SAVE_DATA = new ArrayList<PlayerSave>();
private static final Map<Integer, WorldData> WORLD_DATA = new ConcurrentHashMap<Integer, WorldData>();
private static final ConcurrentHashMap<Integer, WorldData> WORLD_DATA = new ConcurrentHashMap<Integer, WorldData>();
public final ConcurrentSet<Network> laserRelayNetworks = new ConcurrentSet<Network>();
private final ISaveHandler handler;
private final int dimension;

View file

@ -59,7 +59,7 @@ public class OreGen implements IWorldGenerator{
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider){
int dimension = world.provider.getDimension();
if(dimension != -1 && dimension != 1){
if(world.getWorldType() != WorldType.FLAT && Util.arrayContains(ArrayUtils.toObject(ConfigIntListValues.ORE_GEN_DIMENSION_BLACKLIST.getValue()), world.provider.getDimension()) < 0){
if(world.getWorldType() != WorldType.FLAT && !ArrayUtils.contains(ConfigIntListValues.ORE_GEN_DIMENSION_BLACKLIST.getValue(), world.provider.getDimension())){
this.generateDefault(world, random, chunkX*16, chunkZ*16);
}
}
@ -94,7 +94,7 @@ public class OreGen implements IWorldGenerator{
@SubscribeEvent
public void onWorldDecoration(DecorateBiomeEvent.Decorate event){
if((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)){
if(Util.arrayContains(ArrayUtils.toObject(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue()), event.getWorld().provider.getDimension()) < 0){
if(!ArrayUtils.contains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension())){
this.generateRice(event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.CANOLA.ordinal(), ConfigIntValues.CANOLA_AMOUNT.getValue(), ConfigBoolValues.DO_CANOLA_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.FLAX.ordinal(), ConfigIntValues.FLAX_AMOUNT.getValue(), ConfigBoolValues.DO_FLAX_GEN.isEnabled(), Material.GRASS, event);

View file

@ -34,6 +34,7 @@ public class FilterSettingsGui extends Gui{
public SmallerButton whitelistButton;
public SmallerButton metaButton;
public SmallerButton nbtButton;
public SmallerButton oredictButton;
public FilterSettingsGui(FilterSettings settings, int x, int y, List<GuiButton> buttonList){
this.theSettings = settings;
@ -47,6 +48,9 @@ public class FilterSettingsGui extends Gui{
this.nbtButton = new SmallerButton(this.theSettings.nbtButtonId, x, y+36, "");
buttonList.add(this.nbtButton);
this.oredictButton = new SmallerButton(this.theSettings.oredictButtonId, x, y+54, "");
buttonList.add(this.oredictButton);
this.update();
}
@ -54,6 +58,7 @@ public class FilterSettingsGui extends Gui{
this.whitelistButton.displayString = (this.theSettings.isWhitelist ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"W";
this.metaButton.displayString = (this.theSettings.respectMeta ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"M";
this.nbtButton.displayString = (this.theSettings.respectNBT ? TextFormatting.DARK_GREEN : TextFormatting.RED)+"N";
this.oredictButton.displayString = (this.theSettings.respectOredict == 0 ? TextFormatting.RED : (this.theSettings.respectOredict == 1 ? TextFormatting.GREEN : TextFormatting.DARK_GREEN))+"O";
}
public void drawHover(int mouseX, int mouseY){
@ -71,5 +76,22 @@ public class FilterSettingsGui extends Gui{
else if(this.nbtButton.isMouseOver()){
GuiUtils.drawHoveringText(Collections.singletonList(TextFormatting.BOLD+(this.theSettings.respectNBT ? "Respecting" : "Ignoring")+" NBT"), mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
}
else if(this.oredictButton.isMouseOver()){
List<String> list = new ArrayList<String>();
list.add(TextFormatting.BOLD+(this.theSettings.respectOredict == 0 ? "Ignoring" : (this.theSettings.respectOredict == 1 ? "Soft Respecting" : "Hard Respecting"))+" OreDictionary");
String type = null;
if(this.theSettings.respectOredict == 1){
type = "only one";
}
else if(this.theSettings.respectOredict == 2){
type = "all";
}
if(type != null){
list.addAll(mc.fontRendererObj.listFormattedStringToWidth("The item being passed only has to contain "+TextFormatting.DARK_GREEN+type+TextFormatting.RESET+" of the OreDictionary tags of the item in the filter.", 200));
}
GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
}
}
}

View file

@ -81,8 +81,8 @@ public class GuiInputter extends GuiContainer{
super.initGui();
if(this.isAdvanced){
this.leftFilter = new FilterSettingsGui(this.tileInputter.leftFilter, this.guiLeft+3, this.guiTop+16, this.buttonList);
this.rightFilter = new FilterSettingsGui(this.tileInputter.rightFilter, this.guiLeft+157, this.guiTop+16, this.buttonList);
this.leftFilter = new FilterSettingsGui(this.tileInputter.leftFilter, this.guiLeft+3, this.guiTop+6, this.buttonList);
this.rightFilter = new FilterSettingsGui(this.tileInputter.rightFilter, this.guiLeft+157, this.guiTop+6, this.buttonList);
}
this.fieldPullStart = new GuiTextField(3000, this.fontRendererObj, this.guiLeft+6, this.guiTop+80+(this.isAdvanced ? OFFSET_ADVANCED : 0), 34, 8);

View file

@ -65,11 +65,11 @@ public class GuiLaserRelayItemWhitelist extends GuiContainer{
public void initGui(){
super.initGui();
this.leftFilter = new FilterSettingsGui(this.tile.leftFilter, this.guiLeft+3, this.guiTop+8, this.buttonList);
this.rightFilter = new FilterSettingsGui(this.tile.rightFilter, this.guiLeft+157, this.guiTop+8, this.buttonList);
this.leftFilter = new FilterSettingsGui(this.tile.leftFilter, this.guiLeft+3, this.guiTop+6, this.buttonList);
this.rightFilter = new FilterSettingsGui(this.tile.rightFilter, this.guiLeft+157, this.guiTop+6, this.buttonList);
this.buttonSmartWhitelistLeft = new SmallerButton(2, this.guiLeft+3, this.guiTop+64, "S");
this.buttonSmartWhitelistRight = new SmallerButton(3, this.guiLeft+157, this.guiTop+64, "S");
this.buttonSmartWhitelistLeft = new SmallerButton(2, this.guiLeft+3, this.guiTop+79, "S");
this.buttonSmartWhitelistRight = new SmallerButton(3, this.guiLeft+157, this.guiTop+79, "S");
this.buttonList.add(this.buttonSmartWhitelistLeft);
this.buttonList.add(this.buttonSmartWhitelistRight);
}

View file

@ -58,7 +58,7 @@ public class GuiRangedCollector extends GuiContainer{
public void initGui(){
super.initGui();
this.filter = new FilterSettingsGui(this.collector.filter, this.guiLeft+3, this.guiTop+16, this.buttonList);
this.filter = new FilterSettingsGui(this.collector.filter, this.guiLeft+3, this.guiTop+6, this.buttonList);
}
@Override

View file

@ -15,6 +15,8 @@ import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
public class FilterSettings{
@ -30,21 +32,27 @@ public class FilterSettings{
public boolean respectNBT;
private boolean lastRespectNBT;
public int respectOredict;
private int lastRecpectOredict;
public final int whitelistButtonId;
public final int metaButtonId;
public final int nbtButtonId;
public final int oredictButtonId;
public FilterSettings(int startSlot, int endSlot, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, int buttonIdStart){
public FilterSettings(int startSlot, int endSlot, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, int defaultRespectOredict, int buttonIdStart){
this.startSlot = startSlot;
this.endSlot = endSlot;
this.isWhitelist = defaultWhitelist;
this.respectMeta = defaultRespectMeta;
this.respectNBT = defaultRespectNBT;
this.respectOredict = defaultRespectOredict;
this.whitelistButtonId = buttonIdStart;
this.metaButtonId = buttonIdStart+1;
this.nbtButtonId = buttonIdStart+2;
this.oredictButtonId = buttonIdStart+3;
}
public void writeToNBT(NBTTagCompound tag, String name){
@ -52,6 +60,7 @@ public class FilterSettings{
compound.setBoolean("Whitelist", this.isWhitelist);
compound.setBoolean("Meta", this.respectMeta);
compound.setBoolean("NBT", this.respectNBT);
compound.setInteger("Oredict", this.respectOredict);
tag.setTag(name, compound);
}
@ -60,16 +69,18 @@ public class FilterSettings{
this.isWhitelist = compound.getBoolean("Whitelist");
this.respectMeta = compound.getBoolean("Meta");
this.respectNBT = compound.getBoolean("NBT");
this.respectOredict = compound.getInteger("Oredict");
}
public boolean needsUpdateSend(){
return this.lastWhitelist != this.isWhitelist || this.lastRespectMeta != this.respectMeta || this.lastRespectNBT != this.respectNBT;
return this.lastWhitelist != this.isWhitelist || this.lastRespectMeta != this.respectMeta || this.lastRespectNBT != this.respectNBT || this.lastRecpectOredict != this.respectOredict;
}
public void updateLasts(){
this.lastWhitelist = this.isWhitelist;
this.lastRespectMeta = this.respectMeta;
this.lastRespectNBT = this.respectNBT;
this.lastRecpectOredict = this.respectOredict;
}
public void onButtonPressed(int id){
@ -82,17 +93,25 @@ public class FilterSettings{
else if(id == this.nbtButtonId){
this.respectNBT = !this.respectNBT;
}
else if(id == this.oredictButtonId){
if(this.respectOredict+1 > 2){
this.respectOredict = 0;
}
else{
this.respectOredict++;
}
}
}
public boolean check(ItemStack stack, ItemStack[] slots){
return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT);
return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectOredict);
}
public static boolean check(ItemStack stack, ItemStack[] slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt){
public static boolean check(ItemStack stack, ItemStack[] slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt, int oredict){
if(stack != null){
for(int i = startSlot; i < endSlot; i++){
if(slots[i] != null){
if(areEqualEnough(slots[i], stack, meta, nbt)){
if(areEqualEnough(slots[i], stack, meta, nbt, oredict)){
return whitelist;
}
else if(slots[i].getItem() instanceof ItemFilter){
@ -100,7 +119,7 @@ public class FilterSettings{
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]);
if(filterSlots != null && filterSlots.length > 0){
for(ItemStack filterSlot : filterSlots){
if(filterSlot != null && areEqualEnough(filterSlot, stack, meta, nbt)){
if(filterSlot != null && areEqualEnough(filterSlot, stack, meta, nbt, oredict)){
return whitelist;
}
}
@ -112,14 +131,54 @@ public class FilterSettings{
return !whitelist;
}
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt){
private static boolean areEqualEnough(ItemStack first, ItemStack second, boolean meta, boolean nbt, int oredict){
if(first.getItem() != second.getItem()){
return false;
}
else{
boolean metaFine = !meta || first.getItemDamage() == second.getItemDamage();
boolean nbtFine = !nbt || ItemStack.areItemStackTagsEqual(first, second);
return metaFine && nbtFine;
if(metaFine && nbtFine){
if(oredict == 0){
return true;
}
else{
int[] firstIds = OreDictionary.getOreIDs(first);
int[] secondIds = OreDictionary.getOreIDs(second);
boolean firstEmpty = ArrayUtils.isEmpty(firstIds);
boolean secondEmpty = ArrayUtils.isEmpty(secondIds);
//Both empty, meaning none has OreDict entries, so they are equal
if(firstEmpty && secondEmpty){
return true;
}
//Only one empty, meaning they are not equal
else if(firstEmpty || secondEmpty){
return false;
}
else{
for(int id : firstIds){
if(ArrayUtils.contains(secondIds, id)){
//Needs to match only one id, so return true on first match
if(oredict == 1){
return true;
}
}
//Needs to match every id, so just return false when no match
else if(oredict == 2){
return false;
}
}
//If oredict mode 1, this will fail because nothing matched
//If oredict mode 2, this will mean nothing hasn't matched
return oredict == 2;
}
}
}
else{
return false;
}
}
}
}

View file

@ -46,8 +46,8 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
private int lastPullSide;
private int lastPullStart;
private int lastPullEnd;
public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, -1000);
public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, -2000);
public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, 0, -2000);
private boolean hasCheckedTilesAround;

View file

@ -28,8 +28,8 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
public final IInventory filterInventory;
private ItemStack[] slots = new ItemStack[24];
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, -1000);
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, -2000);
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, 0, -2000);
public TileEntityLaserRelayItemWhitelist(){
super("laserRelayItemWhitelist");
@ -212,7 +212,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
ItemStack copy = stack.copy();
copy.stackSize = 1;
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT)){
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectOredict)){
for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){
if(this.slots[k] != null){
if(this.slots[k].getItem() instanceof ItemFilter){

View file

@ -25,7 +25,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
public static final int WHITELIST_START = 6;
public static final int RANGE = 6;
public FilterSettings filter = new FilterSettings(WHITELIST_START, WHITELIST_START+12, true, true, false, -1000);
public FilterSettings filter = new FilterSettings(WHITELIST_START, WHITELIST_START+12, true, true, false, 0, -1000);
public TileEntityRangedCollector(){
super(18, "rangedCollector");

View file

@ -41,15 +41,4 @@ public final class Util{
public static boolean isDevVersion(){
return ModUtil.VERSION.equals("@VERSION@");
}
public static int arrayContains(Object[] array, Object obj){
if(obj != null){
for(int i = 0; i < array.length; i++){
if(array[i] != null && (obj == array[i] || array[i].equals(obj))){
return i;
}
}
}
return -1;
}
}