make StatementParameters use NBT for serialization, add Blueprint Library debug code

This commit is contained in:
asiekierka 2014-11-01 09:42:53 +01:00
parent da8d4513c4
commit ce1daeecf1
19 changed files with 89 additions and 52 deletions

View file

@ -14,10 +14,10 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
public final class StatementManager {
@ -174,7 +174,6 @@ public final class StatementManager {
}
for (Class<? extends IStatementParameter> parameter : parameters.values()) {
System.out.println("registring parameter icons: " + parameter.getCanonicalName());
createParameter(parameter).registerIcons(register);
}
}

View file

@ -1,3 +1,11 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.statements;
public final class StatementMouseClick {

View file

@ -12,11 +12,9 @@ import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.core.NetworkData;
public class StatementParameterItemStack implements IStatementParameter {
@NetworkData
protected ItemStack stack;
@Override

View file

@ -260,12 +260,12 @@ public class BuildCraftBuilders extends BuildCraftMod {
try {
PrintWriter writer = new PrintWriter("SchematicDebug.txt", "UTF-8");
writer.println("*** REGISTERED SCHEMATICS ***");
SchematicRegistry reg = ((SchematicRegistry) BuilderAPI.schematicRegistry);
SchematicRegistry reg = (SchematicRegistry) BuilderAPI.schematicRegistry;
for (BlockMetaPair p : reg.schematicBlocks.keySet()) {
writer.println(p.toString() + " -> " + reg.schematicBlocks.get(p).clazz.getCanonicalName());
}
writer.close();
} catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}

View file

@ -13,7 +13,6 @@ import java.util.EnumMap;
import org.apache.logging.log4j.Level;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.Packet;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
import cpw.mods.fml.common.network.FMLOutboundHandler;

View file

@ -53,7 +53,6 @@ import buildcraft.core.InterModComms;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.PowerMode;
import buildcraft.core.Version;
import buildcraft.core.blueprints.SchematicRegistry;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.silicon.ItemRedstoneChipset.Chipset;
@ -524,7 +523,7 @@ public class BuildCraftTransport extends BuildCraftMod {
}
}
writer.close();
} catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}

View file

@ -8,12 +8,9 @@
*/
package buildcraft.builders;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

View file

@ -3,11 +3,6 @@ package buildcraft.builders;
import java.util.BitSet;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
@ -18,13 +13,13 @@ import buildcraft.builders.schematics.SchematicTileCreative;
import buildcraft.core.blueprints.SchematicRegistry;
public final class HeuristicBlockDetection {
private static BitSet craftableBlockList = new BitSet(65536);
private HeuristicBlockDetection() {
}
private static BitSet craftableBlockList = new BitSet(65536);
public static void start() {
// Initialize craftableBlockList
/* for (Object or : CraftingManager.getInstance().getRecipeList()) {

View file

@ -12,7 +12,6 @@ import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

View file

@ -10,12 +10,14 @@ package buildcraft.core.network;
import java.io.IOException;
import buildcraft.api.core.BCLog;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.core.BCLog;
public class PacketNBT extends PacketCoordinates {
private NBTTagCompound nbttagcompound;

View file

@ -21,16 +21,14 @@ import java.util.Map;
import java.util.TreeMap;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.core.JavaTools;
import buildcraft.api.core.NetworkData;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.network.INBTSerializable;
import buildcraft.core.network.NetworkIdRegistry;
@ -675,5 +673,6 @@ public class ClassMapping extends ClassSerializer {
registerSerializer(Long.class, new SerializerLong());
registerSerializer(BitSet.class, new SerializerBitSet());
registerSerializer(INBTSerializable.class, new SerializerINBTSerializable());
registerSerializer(IStatementParameter.class, new SerializerIStatementParameter());
}
}

View file

@ -0,0 +1,49 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.network.serializers;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementManager;
import buildcraft.core.utils.Utils;
/**
* An NBT-based serializer for IStatementParameters.
*/
public class SerializerIStatementParameter extends ClassSerializer {
@Override
public void write (ByteBuf data, Object o, SerializationContext context) {
IStatementParameter parameter = (IStatementParameter) o;
if (parameter == null) {
data.writeBoolean(false);
} else {
NBTTagCompound cpt = new NBTTagCompound();
parameter.writeToNBT(cpt);
data.writeBoolean(true);
Utils.writeUTF(data, parameter.getUniqueTag());
Utils.writeNBT(data, cpt);
}
}
@Override
public Object read (ByteBuf data, Object o, SerializationContext context) {
if (!data.readBoolean()) {
return null;
} else {
String kind = Utils.readUTF(data);
IStatementParameter parameter = StatementManager.createParameter(kind);
parameter.readFromNBT(Utils.readNBT(data));
return parameter;
}
}
}

View file

@ -10,11 +10,11 @@ package buildcraft.core.statements;
import java.util.Locale;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.statements.IActionExternal;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;

View file

@ -14,22 +14,19 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.IGate;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementMouseClick;
import buildcraft.api.transport.IPipe;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.TileGenericPipe;
public class StatementParameterDirection implements IStatementParameter {
@NetworkData
public ForgeDirection direction = ForgeDirection.UNKNOWN;
private static IIcon[] icons;
public ForgeDirection direction = ForgeDirection.UNKNOWN;
public StatementParameterDirection() {
}

View file

@ -13,11 +13,11 @@ import buildcraft.core.utils.StringUtils;
public class StatementParameterRedstoneGateSideOnly implements
IStatementParameter {
@NetworkData
public boolean isOn = false;
private static IIcon icon;
public boolean isOn = false;
public StatementParameterRedstoneGateSideOnly() {
}

View file

@ -31,13 +31,11 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.StatementManager;
import buildcraft.api.transport.IPipePluggable;
import buildcraft.api.transport.IPipeTile;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.NetworkIdRegistry;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Gate;
import buildcraft.transport.TileGenericPipe;

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementParameter;
@ -250,11 +251,13 @@ public class ContainerGateInterface extends BuildCraftContainer {
IStatement trigger = gate.getTrigger(position);
RPCHandler.rpcPlayer(player, this, "setAction", position, action != null ? action.getUniqueTag() : null, false);
RPCHandler.rpcPlayer(player, this, "setTrigger", position, trigger != null ? trigger.getUniqueTag() : null, false);
for (int p = 0; p < 3; ++p) {
for (int p = 0; p < gate.material.numActionParameters; ++p) {
RPCHandler.rpcPlayer(player, this, "setActionParameter", position, p,
gate.getActionParameter(position, p), false);
RPCHandler.rpcPlayer(player, this, "setTriggerParameter", position, p,
gate.getTriggerParameter(position, p), false);
}
for (int q = 0; q < gate.material.numTriggerParameters; ++q) {
RPCHandler.rpcPlayer(player, this, "setTriggerParameter", position, q,
gate.getTriggerParameter(position, q), false);
}
}
}
@ -388,7 +391,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
RPCHandler.rpcServer(this, "setActionParameter", action, param, parameter, false);
}
}
/**
* GATE INFORMATION *
*/

View file

@ -23,11 +23,11 @@ import buildcraft.api.transport.PipeWire;
import buildcraft.core.utils.StringUtils;
public class ActionParameterSignal implements IStatementParameter {
@NetworkData
public PipeWire color = null;
private static IIcon[] icons;
public PipeWire color = null;
public ActionParameterSignal() {
}

View file

@ -21,19 +21,14 @@ import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementMouseClick;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Gate;
import buildcraft.transport.Pipe;
public class TriggerParameterSignal implements IStatementParameter {
@NetworkData
public boolean active = false;
@NetworkData
public PipeWire color = null;
private static IIcon[] icons;
public boolean active = false;
public PipeWire color = null;
public TriggerParameterSignal() {
}