Cardboard Box blacklist
This commit is contained in:
parent
733bdd5691
commit
30782caa8b
7 changed files with 191 additions and 12 deletions
|
@ -3,6 +3,7 @@ package mekanism.api;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraftforge.event.Event;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class MekanismAPI
|
||||
|
@ -33,7 +34,12 @@ public class MekanismAPI
|
|||
cardboardBoxIgnore.remove(new BlockInfo(id, meta));
|
||||
}
|
||||
|
||||
private static class BlockInfo
|
||||
public static Set<BlockInfo> getBoxIgnore()
|
||||
{
|
||||
return cardboardBoxIgnore;
|
||||
}
|
||||
|
||||
public static class BlockInfo
|
||||
{
|
||||
public int id;
|
||||
public int meta;
|
||||
|
@ -61,4 +67,6 @@ public class MekanismAPI
|
|||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BoxBlacklistEvent extends Event {}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package mekanism.client;
|
||||
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.MekanismAPI.BoxBlacklistEvent;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.client.voice.VoiceClient;
|
||||
import mekanism.common.Mekanism;
|
||||
|
@ -7,6 +9,7 @@ import mekanism.common.PacketHandler;
|
|||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketKey;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
@ -54,6 +57,9 @@ public class MekanismClient extends Mekanism
|
|||
ClientTickHandler.tickingSet.clear();
|
||||
Mekanism.proxy.unloadSoundHandler();
|
||||
|
||||
MekanismAPI.getBoxIgnore().clear();
|
||||
MinecraftForge.EVENT_BUS.post(new BoxBlacklistEvent());
|
||||
|
||||
Mekanism.jetpackOn.clear();
|
||||
Mekanism.gasmaskOn.clear();
|
||||
|
||||
|
|
97
common/mekanism/common/BoxBlacklistParser.java
Normal file
97
common/mekanism/common/BoxBlacklistParser.java
Normal file
|
@ -0,0 +1,97 @@
|
|||
package mekanism.common;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import mekanism.api.MekanismAPI;
|
||||
|
||||
public final class BoxBlacklistParser
|
||||
{
|
||||
public static File mekanismDir = new File(Mekanism.proxy.getMinecraftDir(), "config/mekanism");
|
||||
public static File boxBlacklistFile = new File(mekanismDir, "BoxBlacklist.txt");
|
||||
|
||||
public static void load()
|
||||
{
|
||||
try {
|
||||
generateFiles();
|
||||
readBlacklist();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateFiles() throws IOException
|
||||
{
|
||||
mekanismDir.mkdirs();
|
||||
|
||||
if(!boxBlacklistFile.exists())
|
||||
{
|
||||
boxBlacklistFile.createNewFile();
|
||||
writeExamples();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInteger(String s)
|
||||
{
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
return true;
|
||||
}
|
||||
catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void readBlacklist() throws IOException
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new FileReader(boxBlacklistFile));
|
||||
int entries = 0;
|
||||
|
||||
String readingLine;
|
||||
int line = 0;
|
||||
|
||||
while((readingLine = reader.readLine()) != null)
|
||||
{
|
||||
line++;
|
||||
|
||||
if(readingLine.startsWith("#"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] split = readingLine.split(":");
|
||||
|
||||
if(split.length != 2 || !isInteger(split[0]) || !isInteger(split[1]))
|
||||
{
|
||||
System.err.println("[Mekanism] BoxBlacklist.txt: Couldn't parse blacklist data on line " + line);
|
||||
}
|
||||
|
||||
MekanismAPI.addBoxBlacklist(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
entries++;
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
System.out.println("[Mekanism] Finished loading Cardboard Box blacklist (loaded " + entries + " entries)");
|
||||
}
|
||||
|
||||
private static void writeExamples() throws IOException
|
||||
{
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(boxBlacklistFile));
|
||||
|
||||
writer.append("# Use this file to tell Mekanism which blocks should not be picked up by a cardboard box.");
|
||||
writer.newLine();
|
||||
|
||||
writer.append("# Proper syntax is \"ID:META\". Example (for stone):");
|
||||
writer.newLine();
|
||||
|
||||
writer.append("# 1:0");
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package mekanism.common;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketBoxBlacklist;
|
||||
import mekanism.common.network.PacketConfigSync;
|
||||
import mekanism.common.network.PacketJetpackData;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackPacket;
|
||||
|
@ -16,6 +17,7 @@ public class CommonPlayerTracker implements IPlayerTracker
|
|||
if(!player.worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketConfigSync().setParams(), player);
|
||||
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketBoxBlacklist().setParams(), player);
|
||||
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketJetpackData().setParams(JetpackPacket.FULL), player);
|
||||
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import mekanism.api.ChemicalPair;
|
|||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.MekanismAPI.BoxBlacklistEvent;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasNetwork.GasTransferEvent;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
|
@ -80,6 +81,7 @@ import mekanism.common.item.ItemShard;
|
|||
import mekanism.common.item.ItemWalkieTalkie;
|
||||
import mekanism.common.multipart.ItemPartTransmitter;
|
||||
import mekanism.common.multipart.MultipartMekanism;
|
||||
import mekanism.common.network.PacketBoxBlacklist;
|
||||
import mekanism.common.network.PacketConfigSync;
|
||||
import mekanism.common.network.PacketConfigurationUpdate;
|
||||
import mekanism.common.network.PacketConfiguratorState;
|
||||
|
@ -105,6 +107,7 @@ import mekanism.common.network.PacketTileEntity;
|
|||
import mekanism.common.network.PacketTransmitterUpdate;
|
||||
import mekanism.common.network.PacketTransmitterUpdate.PacketType;
|
||||
import mekanism.common.network.PacketWalkieTalkieState;
|
||||
import mekanism.common.recipe.BinRecipe;
|
||||
import mekanism.common.recipe.MekanismRecipe;
|
||||
import mekanism.common.recipe.RecipeHandler;
|
||||
import mekanism.common.tank.DynamicTankCache;
|
||||
|
@ -1154,15 +1157,6 @@ public class Mekanism
|
|||
addRecipes();
|
||||
addEntities();
|
||||
|
||||
MekanismAPI.addBoxBlacklist(BoundingBlock.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.bedrock.blockID, 0);
|
||||
MekanismAPI.addBoxBlacklist(Block.portal.blockID, 0);
|
||||
MekanismAPI.addBoxBlacklist(Block.endPortal.blockID, 0);
|
||||
MekanismAPI.addBoxBlacklist(Block.endPortalFrame.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.bed.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.doorWood.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.doorIron.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
|
||||
registerOreDict();
|
||||
|
||||
new MultipartMekanism();
|
||||
|
@ -1192,6 +1186,7 @@ public class Mekanism
|
|||
PacketHandler.registerPacket(PacketKey.class);
|
||||
PacketHandler.registerPacket(PacketScubaTankData.class);
|
||||
PacketHandler.registerPacket(PacketConfigSync.class);
|
||||
PacketHandler.registerPacket(PacketBoxBlacklist.class);
|
||||
|
||||
//Donators
|
||||
donators.add("mrgreaper");
|
||||
|
@ -1218,7 +1213,7 @@ public class Mekanism
|
|||
proxy.loadSoundHandler();
|
||||
hooks.hook();
|
||||
|
||||
MekanismAPI.addBoxBlacklist(MultipartProxy.block().blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MinecraftForge.EVENT_BUS.post(new BoxBlacklistEvent());
|
||||
|
||||
addIntegratedItems();
|
||||
|
||||
|
@ -1273,6 +1268,22 @@ public class Mekanism
|
|||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onBlacklistUpdate(BoxBlacklistEvent event)
|
||||
{
|
||||
MekanismAPI.addBoxBlacklist(BoundingBlock.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.bedrock.blockID, 0);
|
||||
MekanismAPI.addBoxBlacklist(Block.portal.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.endPortal.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.endPortalFrame.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.bed.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.doorWood.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(Block.doorIron.blockID, OreDictionary.WILDCARD_VALUE);
|
||||
MekanismAPI.addBoxBlacklist(MultipartProxy.block().blockID, OreDictionary.WILDCARD_VALUE);
|
||||
|
||||
BoxBlacklistParser.load();
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public synchronized void onChunkLoad(ChunkEvent.Load event)
|
||||
{
|
||||
|
|
54
common/mekanism/common/network/PacketBoxBlacklist.java
Normal file
54
common/mekanism/common/network/PacketBoxBlacklist.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import mekanism.api.MekanismAPI;
|
||||
import mekanism.api.MekanismAPI.BlockInfo;
|
||||
import mekanism.common.IModule;
|
||||
import mekanism.common.Mekanism;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
public class PacketBoxBlacklist implements IMekanismPacket
|
||||
{
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "BoxBlacklist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMekanismPacket setParams(Object... data)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
|
||||
{
|
||||
MekanismAPI.getBoxIgnore().clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
MekanismAPI.addBoxBlacklist(dataStream.readInt(), dataStream.readInt());
|
||||
}
|
||||
|
||||
System.out.println("[Mekanism] Received Cardboard Box blacklist entries from server (" + amount + " total)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream dataStream) throws Exception
|
||||
{
|
||||
dataStream.writeInt(MekanismAPI.getBoxIgnore().size());
|
||||
|
||||
for(BlockInfo info : MekanismAPI.getBoxIgnore())
|
||||
{
|
||||
dataStream.writeInt(info.id);
|
||||
dataStream.writeInt(info.meta);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package mekanism.common;
|
||||
package mekanism.common.recipe;
|
||||
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.inventory.InventoryBin;
|
||||
import mekanism.common.item.ItemBlockBasic;
|
||||
import mekanism.common.item.ItemProxy;
|
Loading…
Reference in a new issue