mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-27 23:45:55 +00:00
Added white/black lists for paint sources for the Painter
This commit is contained in:
1 parent
29f9f034af
commit
b126889a0e
13 files changed
+339
-33
No files matched your search
@@ -1,13 +1,14 @@
|
||||
package crazypants.enderio;
|
||||
|
||||
import static crazypants.enderio.EnderIO.*;
|
||||
import static crazypants.enderio.EnderIO.MODID;
|
||||
import static crazypants.enderio.EnderIO.MOD_NAME;
|
||||
import static crazypants.enderio.EnderIO.VERSION;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.List;
|
||||
|
||||
import crazypants.enderio.conduit.redstone.ConduitBundledRedstoneProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -52,6 +53,7 @@ import crazypants.enderio.conduit.item.filter.ItemModItemFilter;
|
||||
import crazypants.enderio.conduit.liquid.ItemLiquidConduit;
|
||||
import crazypants.enderio.conduit.me.ItemMEConduit;
|
||||
import crazypants.enderio.conduit.power.ItemPowerConduit;
|
||||
import crazypants.enderio.conduit.redstone.ConduitBundledRedstoneProvider;
|
||||
import crazypants.enderio.conduit.redstone.ItemRedstoneConduit;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.enderface.BlockEnderIO;
|
||||
@@ -102,6 +104,7 @@ import crazypants.enderio.machine.painter.BlockPaintedSlab;
|
||||
import crazypants.enderio.machine.painter.BlockPaintedStair;
|
||||
import crazypants.enderio.machine.painter.BlockPaintedWall;
|
||||
import crazypants.enderio.machine.painter.BlockPainter;
|
||||
import crazypants.enderio.machine.painter.PaintSourceValidator;
|
||||
import crazypants.enderio.machine.power.BlockCapacitorBank;
|
||||
import crazypants.enderio.machine.reservoir.BlockReservoir;
|
||||
import crazypants.enderio.machine.slicensplice.BlockSliceAndSplice;
|
||||
@@ -567,6 +570,7 @@ public class EnderIO {
|
||||
EnchanterRecipeManager.getInstance().loadRecipesFromConfig();
|
||||
FarmersRegistry.addFarmers();
|
||||
SoulBinderRecipeManager.getInstance().addDefaultRecipes();
|
||||
PaintSourceValidator.instance.loadConfig();
|
||||
|
||||
if(fluidXpJuice == null) { //should have been registered by open blocks
|
||||
fluidXpJuice = FluidRegistry.getFluid("xpjuice");
|
||||
|
||||
@@ -28,6 +28,7 @@ import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.MachineRecipeRegistry;
|
||||
import crazypants.enderio.machine.painter.BasicPainterTemplate;
|
||||
import crazypants.enderio.machine.painter.IPaintedBlock;
|
||||
import crazypants.enderio.machine.painter.PaintSourceValidator;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.enderio.machine.painter.TileEntityPaintedBlock;
|
||||
import crazypants.util.Util;
|
||||
@@ -143,13 +144,14 @@ public class BlockDarkSteelPressurePlate extends BlockPressurePlate implements I
|
||||
items.add(new ItemStack(this, 1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void func_150062_a(World world, int x, int y, int z, int p_150062_5_) {
|
||||
int i1 = this.func_150065_e(world, x, y, z);
|
||||
int i1 = func_150065_e(world, x, y, z);
|
||||
boolean flag = p_150062_5_ > 0;
|
||||
boolean flag1 = i1 > 0;
|
||||
|
||||
if(p_150062_5_ != i1) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, this.func_150066_d(i1), 2);
|
||||
world.setBlockMetadataWithNotify(x, y, z, func_150066_d(i1), 2);
|
||||
func_150064_a_(world, x, y, z);
|
||||
world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
|
||||
}
|
||||
@@ -161,14 +163,14 @@ public class BlockDarkSteelPressurePlate extends BlockPressurePlate implements I
|
||||
}
|
||||
if(playSound) {
|
||||
if(!flag1 && flag) {
|
||||
world.playSoundEffect((double) x + 0.5D, (double) y + 0.1D, (double) z + 0.5D, "random.click", 0.3F, 0.5F);
|
||||
world.playSoundEffect(x + 0.5D, y + 0.1D, z + 0.5D, "random.click", 0.3F, 0.5F);
|
||||
} else if(flag1 && !flag) {
|
||||
world.playSoundEffect((double) x + 0.5D, (double) y + 0.1D, (double) z + 0.5D, "random.click", 0.3F, 0.6F);
|
||||
world.playSoundEffect(x + 0.5D, y + 0.1D, z + 0.5D, "random.click", 0.3F, 0.6F);
|
||||
}
|
||||
}
|
||||
|
||||
if(flag1) {
|
||||
world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world));
|
||||
world.scheduleBlockUpdate(x, y, z, this, tickRate(world));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +180,9 @@ public class BlockDarkSteelPressurePlate extends BlockPressurePlate implements I
|
||||
super(dspp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPaintSource(ItemStack paintSource) {
|
||||
if(BasicPainterTemplate.isValidSourceDefault(paintSource)) {
|
||||
if(PaintSourceValidator.instance.isValidSourceDefault(paintSource)) {
|
||||
return true;
|
||||
}
|
||||
if(paintSource == null) {
|
||||
|
||||
@@ -319,7 +319,6 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
|
||||
@Override
|
||||
public boolean canRenderInPass(int pass) {
|
||||
theRenderPass = pass;
|
||||
System.out.println(pass);
|
||||
return pass == 0 || pass == 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.gui.IAdvancedTooltipProvider;
|
||||
import crazypants.enderio.gui.TooltipAddera;
|
||||
import crazypants.enderio.machine.MachineRecipeInput;
|
||||
import crazypants.enderio.machine.painter.BasicPainterTemplate;
|
||||
import crazypants.enderio.machine.painter.IPaintedBlock;
|
||||
import crazypants.enderio.machine.painter.PaintSourceValidator;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.util.Util;
|
||||
|
||||
@@ -142,6 +142,12 @@ public class ItemConduitFacade extends Item implements IAdvancedTooltipProvider
|
||||
if(block == null || block instanceof IPaintedBlock) {
|
||||
return false;
|
||||
}
|
||||
if(PaintSourceValidator.instance.isBlacklisted(paintSource)) {
|
||||
return false;
|
||||
}
|
||||
if(PaintSourceValidator.instance.isWhitelisted(paintSource)) {
|
||||
return true;
|
||||
}
|
||||
if(!Config.allowTileEntitiesAsPaintSource && block instanceof ITileEntityProvider) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package crazypants.enderio.machine.painter;
|
||||
|
||||
import static crazypants.enderio.machine.MachineRecipeInput.*;
|
||||
import static crazypants.enderio.machine.MachineRecipeInput.getInputForSlot;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.enderio.ModObject;
|
||||
@@ -20,25 +18,10 @@ public abstract class BasicPainterTemplate implements IMachineRecipe {
|
||||
|
||||
public static int DEFAULT_ENERGY_PER_TASK = Config.painterEnergyPerTaskRF;
|
||||
|
||||
public static boolean isValidSourceDefault(ItemStack paintSource) {
|
||||
if(paintSource == null) {
|
||||
return false;
|
||||
}
|
||||
Block block = Util.getBlockFromItemId(paintSource);
|
||||
if(block == null || block instanceof IPaintedBlock) {
|
||||
return false;
|
||||
}
|
||||
if(!Config.allowTileEntitiesAsPaintSource && block instanceof ITileEntityProvider) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return block.isOpaqueCube() || (block.getMaterial().isOpaque() && block.renderAsNormalBlock()) || block == Blocks.glass;
|
||||
}
|
||||
|
||||
protected final Block[] validTargets;
|
||||
|
||||
protected BasicPainterTemplate(Block... validTargetBlocks) {
|
||||
this.validTargets = validTargetBlocks;
|
||||
validTargets = validTargetBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +74,7 @@ public abstract class BasicPainterTemplate implements IMachineRecipe {
|
||||
}
|
||||
|
||||
public boolean isValidPaintSource(ItemStack paintSource) {
|
||||
return isValidSourceDefault(paintSource);
|
||||
return PaintSourceValidator.instance.isValidSourceDefault(paintSource);
|
||||
}
|
||||
|
||||
public boolean isValidTarget(ItemStack target) {
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
package crazypants.enderio.machine.painter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.recipe.RecipeConfig;
|
||||
import crazypants.enderio.machine.recipe.RecipeConfigParser;
|
||||
import crazypants.enderio.machine.recipe.RecipeInput;
|
||||
|
||||
public class PaintSourceParser extends DefaultHandler {
|
||||
|
||||
private static final String CORE_FILE_NAME = "PainterPaintSources_Core.xml";
|
||||
private static final String CUSTOM_FILE_NAME = "PainterPaintSources_User.xml";
|
||||
|
||||
public static void loadConfig() {
|
||||
File coreFile = new File(Config.configDirectory, CORE_FILE_NAME);
|
||||
|
||||
String defaultVals = null;
|
||||
try {
|
||||
defaultVals = RecipeConfig.readRecipes(coreFile, CORE_FILE_NAME, true);
|
||||
} catch (IOException e) {
|
||||
Log.error("Could not load painter lists " + coreFile + " from EnderIO jar: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if(!coreFile.exists()) {
|
||||
Log.error("Could not load default lists from " + coreFile + " as the file does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
parse(defaultVals);
|
||||
} catch (Exception e) {
|
||||
Log.error("Could not parse default lists from " + coreFile + ": " + e);
|
||||
}
|
||||
|
||||
File userFile = new File(Config.configDirectory, CUSTOM_FILE_NAME);
|
||||
String userConfigStr = null;
|
||||
try {
|
||||
userConfigStr = RecipeConfig.readRecipes(userFile, CUSTOM_FILE_NAME, false);
|
||||
if(userConfigStr == null || userConfigStr.trim().length() == 0) {
|
||||
Log.error("Empty user config file: " + userFile.getAbsolutePath());
|
||||
} else {
|
||||
parse(userConfigStr);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.error("Could not load user defined painter lists from file: " + CUSTOM_FILE_NAME);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void parse(String str) throws Exception {
|
||||
StringReader reader = new StringReader(str);
|
||||
InputSource is = new InputSource(reader);
|
||||
try {
|
||||
parse(is);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void parse(InputSource is) throws Exception {
|
||||
PaintSourceParser parser = new PaintSourceParser();
|
||||
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setNamespaceAware(true);
|
||||
SAXParser saxParser = spf.newSAXParser();
|
||||
XMLReader xmlReader = saxParser.getXMLReader();
|
||||
xmlReader.setContentHandler(parser);
|
||||
xmlReader.parse(is);
|
||||
}
|
||||
|
||||
public static final String ELEMENT_WHITELIST = "whitelist";
|
||||
public static final String ELEMENT_BLACKLIST = "blacklist";
|
||||
public static final String ELEMENT_ITEM_STACK = "itemStack";
|
||||
|
||||
private static final String AT_REMOVE = "remove";
|
||||
|
||||
private boolean isWhitelist = false;
|
||||
private boolean isBlacklist = false;
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if(ELEMENT_WHITELIST.equals(localName)) {
|
||||
isWhitelist = true;
|
||||
isBlacklist = false;
|
||||
return;
|
||||
}
|
||||
if(ELEMENT_BLACKLIST.equals(localName)) {
|
||||
isWhitelist = false;
|
||||
isBlacklist = true;
|
||||
return;
|
||||
}
|
||||
if(ELEMENT_ITEM_STACK.equals(localName)) {
|
||||
if(!isWhitelist && !isBlacklist) {
|
||||
Log.warn("PaintSourceParser: Item stack found outside of whitlist/blacklist elements. It will be ignored");
|
||||
return;
|
||||
}
|
||||
RecipeInput stack = RecipeConfigParser.getItemStack(attributes);
|
||||
if(stack == null) {
|
||||
return;
|
||||
}
|
||||
boolean isRemove = RecipeConfigParser.getBooleanValue(AT_REMOVE, attributes, false);
|
||||
if(isBlacklist) {
|
||||
if(isRemove) {
|
||||
PaintSourceValidator.instance.removeFromBlackList(stack);
|
||||
} else {
|
||||
PaintSourceValidator.instance.addToBlacklist(stack);
|
||||
}
|
||||
} else {
|
||||
if(isRemove) {
|
||||
PaintSourceValidator.instance.removeFromWhitelist(stack);
|
||||
} else {
|
||||
PaintSourceValidator.instance.addToWhitelist(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
if(ELEMENT_WHITELIST.equals(localName)) {
|
||||
isWhitelist = false;
|
||||
return;
|
||||
}
|
||||
if(ELEMENT_BLACKLIST.equals(localName)) {
|
||||
isBlacklist = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package crazypants.enderio.machine.painter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.recipe.RecipeInput;
|
||||
import crazypants.util.ItemUtil;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class PaintSourceValidator {
|
||||
|
||||
public static PaintSourceValidator instance = new PaintSourceValidator();
|
||||
|
||||
private boolean listsPopulated = false;
|
||||
private final List<RecipeInput> whitelist = new ArrayList<RecipeInput>();
|
||||
private final List<RecipeInput> blacklist = new ArrayList<RecipeInput>();
|
||||
|
||||
public boolean isValidSourceDefault(ItemStack paintSource) {
|
||||
if(paintSource == null) {
|
||||
return false;
|
||||
}
|
||||
Block block = Util.getBlockFromItemId(paintSource);
|
||||
if(block == null || block instanceof IPaintedBlock) {
|
||||
return false;
|
||||
}
|
||||
if(isBlacklisted(paintSource)) {
|
||||
return false;
|
||||
}
|
||||
if(isWhitelisted(paintSource)) {
|
||||
return true;
|
||||
}
|
||||
if(!Config.allowTileEntitiesAsPaintSource && block instanceof ITileEntityProvider) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return block.isOpaqueCube() || (block.getMaterial().isOpaque() && block.renderAsNormalBlock()) || block == Blocks.glass;
|
||||
}
|
||||
|
||||
public boolean isWhitelisted(ItemStack paintSource) {
|
||||
return isInList(paintSource, whitelist);
|
||||
}
|
||||
|
||||
public boolean isBlacklisted(ItemStack paintSource) {
|
||||
return isInList(paintSource, blacklist);
|
||||
}
|
||||
|
||||
public void addToWhitelist(ItemStack input) {
|
||||
addToWhitelist(new RecipeInput(input, true));
|
||||
}
|
||||
|
||||
public void addToWhitelist(RecipeInput input) {
|
||||
whitelist.add(input);
|
||||
}
|
||||
|
||||
public void addToBlacklist(ItemStack input) {
|
||||
addToBlacklist(new RecipeInput(input, true));
|
||||
}
|
||||
|
||||
public void addToBlacklist(RecipeInput input) {
|
||||
blacklist.add(input);
|
||||
}
|
||||
|
||||
public void removeFromWhitelist(RecipeInput input) {
|
||||
removeFromList(input, whitelist);
|
||||
}
|
||||
|
||||
public void removeFromBlackList(RecipeInput input) {
|
||||
removeFromList(input, blacklist);
|
||||
}
|
||||
|
||||
protected boolean isInList(ItemStack paintSource, List<RecipeInput> list) {
|
||||
if(paintSource == null) {
|
||||
return false;
|
||||
}
|
||||
for (RecipeInput ri : list) {
|
||||
if(ri != null && ri.isInput(paintSource)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void removeFromList(RecipeInput input, List<RecipeInput> list) {
|
||||
ItemStack inStack = input.getInput();
|
||||
if(inStack == null) {
|
||||
return;
|
||||
}
|
||||
RecipeInput toRemove = null;
|
||||
for (RecipeInput in : list) {
|
||||
if(ItemUtil.areStacksEqual(inStack, in.getInput())) {
|
||||
toRemove = in;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(toRemove != null) {
|
||||
list.remove(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
PaintSourceParser.loadConfig();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class TileEntityPainter extends AbstractPoweredTaskEntity implements ISid
|
||||
}
|
||||
}
|
||||
}
|
||||
return BasicPainterTemplate.isValidSourceDefault(itemStack);
|
||||
return PaintSourceValidator.instance.isValidSourceDefault(itemStack);
|
||||
}
|
||||
return MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(),
|
||||
i == 0 ? MachineRecipeInput.create(0, itemStack) : targetInput(), i == 1 ? MachineRecipeInput.create(1, itemStack) : paintSource()) != null;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class RecipeConfig {
|
||||
return config;
|
||||
}
|
||||
|
||||
private static String readRecipes(File copyTo, String fileName, boolean replaceIfExists) throws IOException {
|
||||
public static String readRecipes(File copyTo, String fileName, boolean replaceIfExists) throws IOException {
|
||||
if(!replaceIfExists && copyTo.exists()) {
|
||||
return readStream(new FileInputStream(copyTo));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user