Refinery fixes + StreamPayload
Added a alternative payload system for update packets that uses data streams instead of arrays. Note: It is not compatible with @TileNetworkData so you will have to handle all the data yourself. Also added a TankManager class to contain commonly needed code for tanks: Serialization, TankInfo, Network Data, etc... The Refinery still needs a fair bit of work, but its mostly limited to the GUI filter code. That needs a complete rewrite of some kind since Fluids aren't items and can't be rendered as such.
This commit is contained in:
parent
d6200ab9a5
commit
bb4b5062bc
32 changed files with 850 additions and 599 deletions
|
@ -9,7 +9,7 @@ package buildcraft;
|
|||
|
||||
import buildcraft.api.fuels.IronEngineCoolant;
|
||||
import buildcraft.api.fuels.IronEngineFuel;
|
||||
import buildcraft.api.recipes.RefineryRecipe;
|
||||
import buildcraft.api.recipes.RefineryRecipes;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.BlockSpring;
|
||||
import buildcraft.core.DefaultProps;
|
||||
|
@ -59,6 +59,7 @@ import net.minecraftforge.event.ForgeSubscribe;
|
|||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@Mod(name = "BuildCraft Energy", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Energy", dependencies = DefaultProps.DEPENDENCY_CORE)
|
||||
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandler.class, clientSideRequired = true, serverSideRequired = true)
|
||||
|
@ -195,7 +196,7 @@ public class BuildCraftEnergy {
|
|||
FluidContainerRegistry.registerFluidContainer(FluidRegistry.getFluidStack("fuel", FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(bucketFuel), new ItemStack(Item.bucketEmpty));
|
||||
}
|
||||
|
||||
RefineryRecipe.registerRefineryRecipe(new RefineryRecipe(FluidRegistry.getFluid("oil"), null, FluidRegistry.getFluid("fuel"), 12, 1));
|
||||
RefineryRecipes.addRecipe(new FluidStack(fluidOil, 1), new FluidStack(fluidFuel, 1), 12, 1);
|
||||
|
||||
// Iron Engine Fuels
|
||||
IronEngineFuel.addFuel("lava", 1, 20000);
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.recipes;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import java.util.Collections;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public class RefineryRecipe implements Comparable<RefineryRecipe> {
|
||||
|
||||
private static SortedSet<RefineryRecipe> recipes = new TreeSet<RefineryRecipe>();
|
||||
|
||||
public static void registerRefineryRecipe(RefineryRecipe recipe) {
|
||||
if (!recipes.contains(recipe)) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static SortedSet<RefineryRecipe> getRecipes() {
|
||||
return Collections.unmodifiableSortedSet(recipes);
|
||||
}
|
||||
|
||||
public static RefineryRecipe findRefineryRecipe(Fluid liquid1, Fluid liquid2) {
|
||||
for (RefineryRecipe recipe : recipes)
|
||||
if (recipe.matches(liquid1, liquid2))
|
||||
return recipe;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final Fluid ingredient1;
|
||||
public final Fluid ingredient2;
|
||||
public final Fluid result;
|
||||
|
||||
public final int energy;
|
||||
public final int delay;
|
||||
|
||||
public RefineryRecipe(Fluid ingredient1, Fluid ingredient2, Fluid result, int energy, int delay) {
|
||||
this.ingredient1 = ingredient1;
|
||||
this.ingredient2 = ingredient2;
|
||||
this.result = result;
|
||||
this.energy = energy;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public boolean matches(Fluid liquid1, Fluid liquid2) {
|
||||
|
||||
// No inputs, return.
|
||||
if (liquid1 == null && liquid2 == null)
|
||||
return false;
|
||||
|
||||
// Return if two ingredients are required but only one was supplied.
|
||||
if ((ingredient1 != null && ingredient2 != null) && (liquid1 == null || liquid2 == null))
|
||||
return false;
|
||||
|
||||
if (ingredient1 != null) {
|
||||
if (ingredient2 == null)
|
||||
return ingredient1.getName().equals(liquid1) || ingredient1.getName().equals(liquid2);
|
||||
else
|
||||
return (ingredient1.getName().equals(liquid1) && ingredient2.getName().equals(liquid2))
|
||||
|| (ingredient2.getName().equals(liquid1) && ingredient1.getName().equals(liquid2));
|
||||
|
||||
} else if (ingredient2 != null)
|
||||
return ingredient2.getName().equals(liquid1) || ingredient2.getName().equals(liquid2);
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// Compares to only the types of source materials.
|
||||
// We consider non-null < null in order that one-ingredient recipe is checked after
|
||||
// the failure of matching two-ingredient recipes which include that liquid.
|
||||
@Override
|
||||
public int compareTo(RefineryRecipe other) {
|
||||
return ComparisonChain.start()
|
||||
.compare(ingredient1.getName(), other.ingredient1.getName())
|
||||
.compare(ingredient2.getName(), other.ingredient2.getName())
|
||||
.result();
|
||||
}
|
||||
|
||||
// equals() should be consistent with compareTo().
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof RefineryRecipe &&
|
||||
Objects.equal(ingredient1, ((RefineryRecipe)obj).ingredient1) &&
|
||||
Objects.equal(ingredient1, ((RefineryRecipe)obj).ingredient2);
|
||||
}
|
||||
|
||||
// hashCode() should be overridden because equals() was overridden.
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(ingredient1, ingredient2);
|
||||
}
|
||||
}
|
126
common/buildcraft/api/recipes/RefineryRecipes.java
Normal file
126
common/buildcraft/api/recipes/RefineryRecipes.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 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.recipes;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import java.util.Collections;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public final class RefineryRecipes {
|
||||
|
||||
private static SortedSet<Recipe> recipes = new TreeSet<Recipe>();
|
||||
|
||||
public static void addRecipe(FluidStack ingredient, FluidStack result, int energy, int delay) {
|
||||
addRecipe(ingredient, null, result, energy, delay);
|
||||
}
|
||||
|
||||
public static void addRecipe(FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay) {
|
||||
Recipe recipe = new Recipe(ingredient1, ingredient2, result, energy, delay);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
public static SortedSet<Recipe> getRecipes() {
|
||||
return Collections.unmodifiableSortedSet(recipes);
|
||||
}
|
||||
|
||||
public static Recipe findRefineryRecipe(FluidStack liquid1, FluidStack liquid2) {
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe.matches(liquid1, liquid2))
|
||||
return recipe;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private RefineryRecipes() {
|
||||
}
|
||||
|
||||
public static final class Recipe implements Comparable<Recipe> {
|
||||
|
||||
public final FluidStack ingredient1;
|
||||
public final FluidStack ingredient2;
|
||||
public final FluidStack result;
|
||||
public final int energy;
|
||||
public final int delay;
|
||||
|
||||
private Recipe(FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay) {
|
||||
if (ingredient1 == null)
|
||||
throw new IllegalArgumentException("First Ingredient cannot be null!");
|
||||
this.ingredient1 = ingredient1;
|
||||
this.ingredient2 = ingredient2;
|
||||
this.result = result;
|
||||
this.energy = energy;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public boolean matches(FluidStack liquid1, FluidStack liquid2) {
|
||||
|
||||
// No inputs, return.
|
||||
if (liquid1 == null && liquid2 == null)
|
||||
return false;
|
||||
|
||||
// Return if two ingredients are required but only one was supplied.
|
||||
if ((ingredient1 != null && ingredient2 != null) && (liquid1 == null || liquid2 == null))
|
||||
return false;
|
||||
|
||||
if (liquid1 != null && liquid2 != null) {
|
||||
if (liquid1.containsFluid(ingredient1) && liquid1.containsFluid(ingredient2))
|
||||
return true;
|
||||
if (liquid1.containsFluid(ingredient2) && liquid1.containsFluid(ingredient1))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (liquid1 != null)
|
||||
return liquid1.containsFluid(ingredient1) || liquid1.containsFluid(ingredient2);
|
||||
|
||||
if (liquid2 != null)
|
||||
return liquid2.containsFluid(ingredient1) || liquid2.containsFluid(ingredient2);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compares to only the types of source materials.
|
||||
// We consider non-null < null in order that one-ingredient recipe is checked after
|
||||
// the failure of matching two-ingredient recipes which include that liquid.
|
||||
@Override
|
||||
public int compareTo(Recipe other) {
|
||||
if (other == null)
|
||||
return -1;
|
||||
else if (ingredient1.getFluid() != other.ingredient1.getFluid())
|
||||
return ingredient1.getFluid().getName().compareTo(other.ingredient1.getFluid().getName());
|
||||
else if (ingredient1.amount != other.ingredient1.amount)
|
||||
return other.ingredient1.amount - ingredient1.amount;
|
||||
else if (ingredient2 == null)
|
||||
return other.ingredient2 == null ? 0 : 1;
|
||||
else if (other.ingredient2 == null)
|
||||
return -1;
|
||||
else if (ingredient2.getFluid() != other.ingredient2.getFluid())
|
||||
return ingredient2.getFluid().getName().compareTo(other.ingredient2.getFluid().getName());
|
||||
else if (ingredient2.amount != other.ingredient2.amount)
|
||||
return other.ingredient2.amount - ingredient2.amount;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// equals() should be consistent with compareTo().
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Recipe
|
||||
&& Objects.equal(ingredient1, ((Recipe) obj).ingredient1)
|
||||
&& Objects.equal(ingredient2, ((Recipe) obj).ingredient2);
|
||||
}
|
||||
|
||||
// hashCode() should be overridden because equals() was overridden.
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(ingredient1, ingredient2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
* Copyright (c) SpaceToad, 2011 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
|
||||
* 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.builders;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -28,20 +26,17 @@ import buildcraft.core.network.PacketUpdate;
|
|||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TileArchitect extends TileBuildCraft implements IInventory {
|
||||
|
||||
public @TileNetworkData
|
||||
Box box = new Box();
|
||||
|
||||
private ItemStack items[] = new ItemStack[2];
|
||||
|
||||
private boolean isComputing = false;
|
||||
public int computingTime = 0;
|
||||
|
||||
public @TileNetworkData
|
||||
String name = "";
|
||||
|
||||
// Use that field to avoid creating several times the same template if
|
||||
// they're the same!
|
||||
private int lastBptId = 0;
|
||||
|
@ -343,7 +338,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleDescriptionPacket(PacketUpdate packet) {
|
||||
public void handleDescriptionPacket(PacketUpdate packet) throws IOException {
|
||||
boolean initialized = box.isInitialized();
|
||||
|
||||
super.handleDescriptionPacket(packet);
|
||||
|
@ -354,7 +349,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
boolean initialized = box.isInitialized();
|
||||
|
||||
super.handleUpdatePacket(packet);
|
||||
|
@ -366,11 +361,9 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
|
||||
@Override
|
||||
public void openChest() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import buildcraft.api.power.PowerHandler.PowerReceiver;
|
|||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.EntityLaser;
|
||||
import buildcraft.core.EntityPowerLaser;
|
||||
import buildcraft.core.EntityRobot;
|
||||
|
@ -34,6 +33,7 @@ import buildcraft.core.network.PacketUpdate;
|
|||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
@ -282,12 +282,12 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
box.initialize(bluePrintBuilder);
|
||||
}
|
||||
|
||||
if (builderRobot == null) {
|
||||
builderRobot = new EntityRobot(worldObj, box);
|
||||
worldObj.spawnEntityInWorld(builderRobot);
|
||||
}
|
||||
if (builderRobot == null) {
|
||||
builderRobot = new EntityRobot(worldObj, box);
|
||||
worldObj.spawnEntityInWorld(builderRobot);
|
||||
}
|
||||
|
||||
box.createLasers(worldObj, LaserKind.Stripes);
|
||||
box.createLasers(worldObj, LaserKind.Stripes);
|
||||
|
||||
|
||||
// builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, this), bluePrintBuilder.getContext());
|
||||
|
@ -519,7 +519,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleDescriptionPacket(PacketUpdate packet) {
|
||||
public void handleDescriptionPacket(PacketUpdate packet) throws IOException {
|
||||
boolean initialized = box.isInitialized();
|
||||
|
||||
super.handleDescriptionPacket(packet);
|
||||
|
@ -530,7 +530,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
boolean initialized = box.isInitialized();
|
||||
|
||||
super.handleUpdatePacket(packet);
|
||||
|
|
|
@ -27,6 +27,7 @@ import buildcraft.core.proxy.CoreProxy;
|
|||
import buildcraft.core.triggers.ActionMachineControl;
|
||||
import buildcraft.core.triggers.ActionMachineControl.Mode;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
|
@ -296,7 +297,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleDescriptionPacket(PacketUpdate packet) {
|
||||
public void handleDescriptionPacket(PacketUpdate packet) throws IOException {
|
||||
boolean initialized = box.isInitialized();
|
||||
|
||||
super.handleDescriptionPacket(packet);
|
||||
|
@ -310,7 +311,7 @@ public class TileFiller extends TileBuildCraft implements ISidedInventory, IPowe
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
boolean initialized = box.isInitialized();
|
||||
|
||||
super.handleUpdatePacket(packet);
|
||||
|
|
|
@ -2,12 +2,12 @@ package buildcraft.builders;
|
|||
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.EntityLaser;
|
||||
import buildcraft.core.EntityPowerLaser;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.TreeSet;
|
||||
|
@ -18,15 +18,12 @@ import net.minecraft.world.World;
|
|||
public class TilePathMarker extends TileMarker {
|
||||
|
||||
public EntityLaser lasers[] = new EntityLaser[2];
|
||||
|
||||
public int x0, y0, z0, x1, y1, z1;
|
||||
public boolean loadLink0 = false, loadLink1 = false;
|
||||
public @TileNetworkData
|
||||
boolean tryingToConnect = false;
|
||||
|
||||
public TilePathMarker links[] = new TilePathMarker[2];
|
||||
public static int searchSize = 64; // TODO: this should be moved to default props
|
||||
|
||||
// A list with the pathMarkers that aren't fully connected
|
||||
// It only contains markers within the loaded chunks
|
||||
private static LinkedList<TilePathMarker> availableMarkers = new LinkedList<TilePathMarker>();
|
||||
|
@ -269,7 +266,7 @@ public class TilePathMarker extends TileMarker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
boolean previousState = tryingToConnect;
|
||||
|
||||
super.handleUpdatePacket(packet);
|
||||
|
|
|
@ -15,6 +15,7 @@ import buildcraft.core.blueprints.BptPlayerIndex;
|
|||
import buildcraft.core.gui.GuiBuildCraft;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadArrays;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
@ -157,7 +158,7 @@ public class GuiBlueprintLibrary extends GuiBuildCraft {
|
|||
|
||||
if (ySlot >= 0 && ySlot <= 11) {
|
||||
if (ySlot < library.currentNames.length) {
|
||||
PacketPayload payload = new PacketPayload();
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays();
|
||||
payload.intPayload = new int[]{ySlot};
|
||||
PacketLibraryAction packet = new PacketLibraryAction(PacketIds.LIBRARY_SELECT, library.xCoord, library.yCoord, library.zCoord);
|
||||
packet.actionId = ySlot;
|
||||
|
|
|
@ -12,6 +12,7 @@ import buildcraft.core.DefaultProps;
|
|||
import buildcraft.core.gui.GuiBuildCraft;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadArrays;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
@ -83,7 +84,7 @@ public class GuiTemplate extends GuiBuildCraft {
|
|||
editMode = false;
|
||||
return;
|
||||
}
|
||||
PacketPayload payload = new PacketPayload();
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays();
|
||||
payload.intPayload = new int[]{c};
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.ARCHITECT_NAME, template.xCoord, template.yCoord, template.zCoord, payload);
|
||||
CoreProxy.proxy.sendToServer(packet.getPacket());
|
||||
|
|
|
@ -3,6 +3,7 @@ package buildcraft.builders.network;
|
|||
import buildcraft.builders.TileArchitect;
|
||||
import buildcraft.builders.TileBlueprintLibrary;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPayloadArrays;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
@ -47,7 +48,7 @@ public class PacketHandlerBuilders implements IPacketHandler {
|
|||
private void onArchitectName(EntityPlayer player, PacketUpdate packet) {
|
||||
TileEntity te = player.worldObj.getBlockTileEntity(packet.posX, packet.posY, packet.posZ);
|
||||
if (te instanceof TileArchitect) {
|
||||
((TileArchitect) te).handleClientInput((char) packet.payload.intPayload[0]);
|
||||
((TileArchitect) te).handleClientInput((char) ((PacketPayloadArrays)packet.payload).intPayload[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,11 +10,13 @@ package buildcraft.core;
|
|||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.core.network.ISynchronizedTile;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadArrays;
|
||||
import buildcraft.core.network.PacketTileUpdate;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.network.TilePacketWrapper;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
|
@ -93,13 +95,15 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleDescriptionPacket(PacketUpdate packet) {
|
||||
descriptionPacket.fromPayload(this, packet.payload);
|
||||
public void handleDescriptionPacket(PacketUpdate packet) throws IOException {
|
||||
if (packet.payload instanceof PacketPayloadArrays)
|
||||
descriptionPacket.fromPayload(this, (PacketPayloadArrays) packet.payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
updatePacket.fromPayload(this, packet.payload);
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
if (packet.payload instanceof PacketPayloadArrays)
|
||||
updatePacket.fromPayload(this, (PacketPayloadArrays) packet.payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
41
common/buildcraft/core/liquids/RestrictedTank.java
Normal file
41
common/buildcraft/core/liquids/RestrictedTank.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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.liquids;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class RestrictedTank extends Tank {
|
||||
|
||||
private final Fluid[] acceptedFluids;
|
||||
|
||||
public RestrictedTank(String name, int capacity, Fluid... acceptedFluids) {
|
||||
super(name, capacity);
|
||||
this.acceptedFluids = acceptedFluids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
if (!acceptsFluid(resource.getFluid()))
|
||||
return 0;
|
||||
return super.fill(resource, doFill);
|
||||
}
|
||||
|
||||
public boolean acceptsFluid(Fluid fluid) {
|
||||
for (Fluid accepted : acceptedFluids) {
|
||||
if (accepted.equals(fluid))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
77
common/buildcraft/core/liquids/Tank.java
Normal file
77
common/buildcraft/core/liquids/Tank.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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.liquids;
|
||||
|
||||
import buildcraft.core.gui.tooltips.ToolTip;
|
||||
import buildcraft.core.gui.tooltips.ToolTipLine;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class Tank extends FluidTank {
|
||||
|
||||
private final String name;
|
||||
|
||||
public Tank(String name, int capacity) {
|
||||
super(capacity);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getFluid() == null || getFluid().amount <= 0;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return getFluid() != null && getFluid().amount >= getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound tankData = new NBTTagCompound();
|
||||
super.writeToNBT(tankData);
|
||||
nbt.setCompoundTag(name, tankData);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTank readFromNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(name)) {
|
||||
NBTTagCompound tankData = nbt.getCompoundTag(name);
|
||||
super.readFromNBT(tankData);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ToolTip getToolTip() {
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
protected void refreshTooltip() {
|
||||
toolTip.clear();
|
||||
int amount = 0;
|
||||
if (getFluid() != null && getFluid().amount > 0) {
|
||||
ToolTipLine fluidName = new ToolTipLine(getFluid().getFluid().getLocalizedName());
|
||||
fluidName.setSpacing(2);
|
||||
toolTip.add(fluidName);
|
||||
amount = getFluid().amount;
|
||||
}
|
||||
toolTip.add(new ToolTipLine(String.format(Locale.ENGLISH, "%,d / %,d", amount, getCapacity())));
|
||||
}
|
||||
protected final ToolTip toolTip = new ToolTip() {
|
||||
@Override
|
||||
public void refresh() {
|
||||
refreshTooltip();
|
||||
}
|
||||
};
|
||||
}
|
133
common/buildcraft/core/liquids/TankManager.java
Normal file
133
common/buildcraft/core/liquids/TankManager.java
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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.liquids;
|
||||
|
||||
import com.google.common.collect.ForwardingList;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class TankManager extends ForwardingList<Tank> implements IFluidHandler, List<Tank> {
|
||||
|
||||
private List<Tank> tanks = new ArrayList<Tank>();
|
||||
|
||||
public TankManager() {
|
||||
}
|
||||
|
||||
public TankManager(Tank... tanks) {
|
||||
addAll(Arrays.asList(tanks));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Tank> delegate() {
|
||||
return tanks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
for (Tank tank : tanks) {
|
||||
int used = tank.fill(resource, doFill);
|
||||
if (used > 0)
|
||||
return used;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
if (resource == null)
|
||||
return null;
|
||||
for (Tank tank : tanks) {
|
||||
if (!resource.isFluidEqual(tank.getFluid()))
|
||||
continue;
|
||||
FluidStack drained = tank.drain(resource.amount, doDrain);
|
||||
if (drained != null && drained.amount > 0)
|
||||
return drained;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
for (Tank tank : tanks) {
|
||||
FluidStack drained = tank.drain(maxDrain, doDrain);
|
||||
if (drained != null && drained.amount > 0)
|
||||
return drained;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
FluidTankInfo[] info = new FluidTankInfo[size()];
|
||||
for (int i = 0; i < size(); i++) {
|
||||
info[i] = get(i).getInfo();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
for (Tank tank : tanks) {
|
||||
tank.writeToNBT(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
for (Tank tank : tanks) {
|
||||
tank.readFromNBT(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
for (Tank tank : tanks) {
|
||||
FluidStack fluidStack = tank.getFluid();
|
||||
if (fluidStack != null) {
|
||||
data.writeShort(fluidStack.getFluid().getID());
|
||||
data.writeInt(fluidStack.amount);
|
||||
} else {
|
||||
data.writeShort(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
for (Tank tank : tanks) {
|
||||
int fluidId = data.readShort();
|
||||
if (fluidId > 0) {
|
||||
tank.setFluid(new FluidStack(fluidId, data.readInt()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,20 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
* Copyright (c) SpaceToad, 2011 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
|
||||
* 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
|
||||
public interface ISynchronizedTile {
|
||||
|
||||
public void handleDescriptionPacket(PacketUpdate packet);
|
||||
public void handleDescriptionPacket(PacketUpdate packet) throws IOException;
|
||||
|
||||
public void handleUpdatePacket(PacketUpdate packet);
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException;
|
||||
|
||||
public void postPacketHandling(PacketUpdate packet);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import cpw.mods.fml.common.network.IPacketHandler;
|
|||
import cpw.mods.fml.common.network.Player;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
@ -12,7 +13,7 @@ import net.minecraft.world.World;
|
|||
|
||||
public class PacketHandler implements IPacketHandler {
|
||||
|
||||
private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) {
|
||||
private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) throws IOException {
|
||||
World world = player.worldObj;
|
||||
|
||||
if (!packet.targetExists(world))
|
||||
|
@ -34,21 +35,21 @@ public class PacketHandler implements IPacketHandler {
|
|||
|
||||
int packetID = data.read();
|
||||
switch (packetID) {
|
||||
case PacketIds.TILE_UPDATE:
|
||||
PacketTileUpdate packetT = new PacketTileUpdate();
|
||||
packetT.readData(data);
|
||||
onTileUpdate((EntityPlayer) player, packetT);
|
||||
break;
|
||||
case PacketIds.TILE_UPDATE:
|
||||
PacketTileUpdate packetT = new PacketTileUpdate();
|
||||
packetT.readData(data);
|
||||
onTileUpdate((EntityPlayer) player, packetT);
|
||||
break;
|
||||
|
||||
case PacketIds.STATE_UPDATE:
|
||||
PacketTileState inPacket = new PacketTileState();
|
||||
inPacket.readData(data);
|
||||
World world = ((EntityPlayer) player).worldObj;
|
||||
TileEntity tile = world.getBlockTileEntity(inPacket.posX, inPacket.posY, inPacket.posZ);
|
||||
if (tile instanceof ISyncedTile) {
|
||||
inPacket.applyStates(data, (ISyncedTile) tile);
|
||||
}
|
||||
break;
|
||||
case PacketIds.STATE_UPDATE:
|
||||
PacketTileState inPacket = new PacketTileState();
|
||||
inPacket.readData(data);
|
||||
World world = ((EntityPlayer) player).worldObj;
|
||||
TileEntity tile = world.getBlockTileEntity(inPacket.posX, inPacket.posY, inPacket.posZ);
|
||||
if (tile instanceof ISyncedTile) {
|
||||
inPacket.applyStates(data, (ISyncedTile) tile);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
|
|
@ -1,57 +1,30 @@
|
|||
package buildcraft.core.network;
|
||||
|
||||
import buildcraft.core.utils.Utils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PacketPayload {
|
||||
public abstract class PacketPayload {
|
||||
|
||||
public int[] intPayload = new int[0];
|
||||
public float[] floatPayload = new float[0];
|
||||
public String[] stringPayload = new String[0];
|
||||
public static enum Type {
|
||||
|
||||
public PacketPayload() {
|
||||
NULL, ARRAY, STREAM
|
||||
}
|
||||
|
||||
public PacketPayload(int intSize, int floatSize, int stringSize) {
|
||||
intPayload = new int[intSize];
|
||||
floatPayload = new float[floatSize];
|
||||
stringPayload = new String[stringSize];
|
||||
public static PacketPayload makePayload(int type) {
|
||||
if (type == Type.ARRAY.ordinal())
|
||||
return new PacketPayloadArrays();
|
||||
if (type == Type.STREAM.ordinal())
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void append(PacketPayload other) {
|
||||
if (other == null)
|
||||
return;
|
||||
public abstract void writeData(DataOutputStream data) throws IOException;
|
||||
|
||||
if (other.intPayload.length > 0) {
|
||||
this.intPayload = Utils.concat(this.intPayload, other.intPayload);
|
||||
}
|
||||
if (other.floatPayload.length > 0) {
|
||||
this.floatPayload = Utils.concat(this.floatPayload, other.floatPayload);
|
||||
}
|
||||
if (other.stringPayload.length > 0) {
|
||||
this.stringPayload = Utils.concat(this.stringPayload, other.stringPayload);
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract void readData(DataInputStream data) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
public void append(int[] other) {
|
||||
if (other == null || other.length < 0)
|
||||
return;
|
||||
|
||||
this.intPayload = Utils.concat(this.intPayload, other);
|
||||
}
|
||||
|
||||
public void splitTail(IndexInPayload index) {
|
||||
PacketPayload payload = new PacketPayload(intPayload.length - index.intIndex, floatPayload.length - index.floatIndex, stringPayload.length
|
||||
- index.stringIndex);
|
||||
|
||||
if (intPayload.length > 0) {
|
||||
System.arraycopy(intPayload, index.intIndex, payload.intPayload, 0, payload.intPayload.length);
|
||||
}
|
||||
if (floatPayload.length > 0) {
|
||||
System.arraycopy(floatPayload, index.floatIndex, payload.floatPayload, 0, payload.floatPayload.length);
|
||||
}
|
||||
if (stringPayload.length > 0) {
|
||||
System.arraycopy(stringPayload, index.stringIndex, payload.stringPayload, 0, payload.stringPayload.length);
|
||||
}
|
||||
}
|
||||
public abstract Type getType();
|
||||
}
|
||||
|
|
111
common/buildcraft/core/network/PacketPayloadArrays.java
Normal file
111
common/buildcraft/core/network/PacketPayloadArrays.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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;
|
||||
|
||||
import buildcraft.core.utils.Utils;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class PacketPayloadArrays extends PacketPayload {
|
||||
|
||||
public int[] intPayload = new int[0];
|
||||
public float[] floatPayload = new float[0];
|
||||
public String[] stringPayload = new String[0];
|
||||
|
||||
public PacketPayloadArrays() {
|
||||
}
|
||||
|
||||
public PacketPayloadArrays(int intSize, int floatSize, int stringSize) {
|
||||
intPayload = new int[intSize];
|
||||
floatPayload = new float[floatSize];
|
||||
stringPayload = new String[stringSize];
|
||||
}
|
||||
|
||||
public void append(PacketPayloadArrays other) {
|
||||
if (other == null)
|
||||
return;
|
||||
|
||||
if (other.intPayload.length > 0) {
|
||||
this.intPayload = Utils.concat(this.intPayload, other.intPayload);
|
||||
}
|
||||
if (other.floatPayload.length > 0) {
|
||||
this.floatPayload = Utils.concat(this.floatPayload, other.floatPayload);
|
||||
}
|
||||
if (other.stringPayload.length > 0) {
|
||||
this.stringPayload = Utils.concat(this.stringPayload, other.stringPayload);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void append(int[] other) {
|
||||
if (other == null || other.length < 0)
|
||||
return;
|
||||
|
||||
this.intPayload = Utils.concat(this.intPayload, other);
|
||||
}
|
||||
|
||||
public void splitTail(IndexInPayload index) {
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(intPayload.length - index.intIndex, floatPayload.length - index.floatIndex, stringPayload.length
|
||||
- index.stringIndex);
|
||||
|
||||
if (intPayload.length > 0) {
|
||||
System.arraycopy(intPayload, index.intIndex, payload.intPayload, 0, payload.intPayload.length);
|
||||
}
|
||||
if (floatPayload.length > 0) {
|
||||
System.arraycopy(floatPayload, index.floatIndex, payload.floatPayload, 0, payload.floatPayload.length);
|
||||
}
|
||||
if (stringPayload.length > 0) {
|
||||
System.arraycopy(stringPayload, index.stringIndex, payload.stringPayload, 0, payload.stringPayload.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeInt(intPayload.length);
|
||||
data.writeInt(floatPayload.length);
|
||||
data.writeInt(stringPayload.length);
|
||||
|
||||
for (int intData : intPayload) {
|
||||
data.writeInt(intData);
|
||||
}
|
||||
for (float floatData : floatPayload) {
|
||||
data.writeFloat(floatData);
|
||||
}
|
||||
for (String stringData : stringPayload) {
|
||||
data.writeUTF(stringData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
intPayload = new int[data.readInt()];
|
||||
floatPayload = new float[data.readInt()];
|
||||
stringPayload = new String[data.readInt()];
|
||||
|
||||
for (int i = 0; i < intPayload.length; i++) {
|
||||
intPayload[i] = data.readInt();
|
||||
}
|
||||
for (int i = 0; i < floatPayload.length; i++) {
|
||||
floatPayload[i] = data.readFloat();
|
||||
}
|
||||
for (int i = 0; i < stringPayload.length; i++) {
|
||||
stringPayload[i] = data.readUTF();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.ARRAY;
|
||||
}
|
||||
}
|
54
common/buildcraft/core/network/PacketPayloadStream.java
Normal file
54
common/buildcraft/core/network/PacketPayloadStream.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) SpaceToad, 2011-2012
|
||||
* 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;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Alternative Packet Payload system.
|
||||
*
|
||||
* Note, you cannot use a Stream payload and the TileNetworkData annotation at
|
||||
* the same time. Attempting to do will most likely result in a class cast
|
||||
* exception somewhere.
|
||||
*
|
||||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class PacketPayloadStream extends PacketPayload {
|
||||
|
||||
public static interface StreamWriter {
|
||||
|
||||
public void writeData(DataOutputStream data) throws IOException;
|
||||
}
|
||||
private StreamWriter handler;
|
||||
public DataInputStream stream;
|
||||
|
||||
public PacketPayloadStream() {
|
||||
}
|
||||
|
||||
public PacketPayloadStream(StreamWriter handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
handler.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
stream = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Type.STREAM;
|
||||
}
|
||||
}
|
|
@ -7,11 +7,9 @@ import java.io.IOException;
|
|||
public class PacketUpdate extends BuildCraftPacket {
|
||||
|
||||
private int packetId;
|
||||
|
||||
public int posX;
|
||||
public int posY;
|
||||
public int posZ;
|
||||
|
||||
public PacketPayload payload;
|
||||
|
||||
public PacketUpdate() {
|
||||
|
@ -44,28 +42,14 @@ public class PacketUpdate extends BuildCraftPacket {
|
|||
data.writeInt(posY);
|
||||
data.writeInt(posZ);
|
||||
|
||||
// No payload means no data
|
||||
if (payload == null) {
|
||||
data.writeInt(0);
|
||||
data.writeInt(0);
|
||||
data.writeInt(0);
|
||||
return;
|
||||
}
|
||||
data.writeByte(payload != null ? payload.getType().ordinal() : 0);
|
||||
|
||||
data.writeInt(payload.intPayload.length);
|
||||
data.writeInt(payload.floatPayload.length);
|
||||
data.writeInt(payload.stringPayload.length);
|
||||
|
||||
for (int intData : payload.intPayload) {
|
||||
data.writeInt(intData);
|
||||
if (payload != null) {
|
||||
data.writeByte(payload.getType().ordinal());
|
||||
payload.writeData(data);
|
||||
} else {
|
||||
data.writeByte(0);
|
||||
}
|
||||
for (float floatData : payload.floatPayload) {
|
||||
data.writeFloat(floatData);
|
||||
}
|
||||
for (String stringData : payload.stringPayload) {
|
||||
data.writeUTF(stringData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,27 +59,16 @@ public class PacketUpdate extends BuildCraftPacket {
|
|||
posY = data.readInt();
|
||||
posZ = data.readInt();
|
||||
|
||||
payload = new PacketPayload();
|
||||
byte type = data.readByte();
|
||||
|
||||
payload.intPayload = new int[data.readInt()];
|
||||
payload.floatPayload = new float[data.readInt()];
|
||||
payload.stringPayload = new String[data.readInt()];
|
||||
|
||||
for (int i = 0; i < payload.intPayload.length; i++) {
|
||||
payload.intPayload[i] = data.readInt();
|
||||
}
|
||||
for (int i = 0; i < payload.floatPayload.length; i++) {
|
||||
payload.floatPayload[i] = data.readFloat();
|
||||
}
|
||||
for (int i = 0; i < payload.stringPayload.length; i++) {
|
||||
payload.stringPayload[i] = data.readUTF();
|
||||
}
|
||||
payload = PacketPayload.makePayload(type);
|
||||
|
||||
if (payload != null)
|
||||
payload.readData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return packetId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class TilePacketWrapper {
|
|||
sizeS += size[2];
|
||||
}
|
||||
|
||||
PacketPayload payload = new PacketPayload(0, sizeF, sizeS);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(0, sizeF, sizeS);
|
||||
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class TilePacketWrapper {
|
|||
sizeS += size[2];
|
||||
}
|
||||
|
||||
PacketPayload payload = new PacketPayload(0, sizeF, sizeS);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(0, sizeF, sizeS);
|
||||
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
|
||||
|
@ -108,7 +108,7 @@ public class TilePacketWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
public void fromPayload(TileEntity tile, PacketPayload packet) {
|
||||
public void fromPayload(TileEntity tile, PacketPayloadArrays packet) {
|
||||
try {
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
buf.writeIntArray(packet.intPayload);
|
||||
|
@ -124,11 +124,11 @@ public class TilePacketWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
public void fromPayload(Object obj, PacketPayload packet) {
|
||||
public void fromPayload(Object obj, PacketPayloadArrays packet) {
|
||||
fromPayload(new Object[] { obj }, packet);
|
||||
}
|
||||
|
||||
public void fromPayload(Object[] obj, PacketPayload packet) {
|
||||
public void fromPayload(Object[] obj, PacketPayloadArrays packet) {
|
||||
try {
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
buf.writeIntArray(packet.intPayload);
|
||||
|
|
|
@ -26,6 +26,7 @@ import buildcraft.core.network.ISynchronizedTile;
|
|||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.energy.TileEngine;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -366,7 +367,7 @@ public class Utils {
|
|||
return lasers;
|
||||
}
|
||||
|
||||
public static void handleBufferedDescription(ISynchronizedTile tileSynch) {
|
||||
public static void handleBufferedDescription(ISynchronizedTile tileSynch) throws IOException {
|
||||
TileEntity tile = (TileEntity) tileSynch;
|
||||
BlockIndex index = new BlockIndex(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ public class BptBlockRefinery extends BptBlock {
|
|||
public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) {
|
||||
TileRefinery refinery = (TileRefinery) context.world().getBlockTileEntity(x, y, z);
|
||||
|
||||
slot.cpt.setInteger("filter0", refinery.getFilter(0));
|
||||
slot.cpt.setInteger("filter1", refinery.getFilter(1));
|
||||
// slot.cpt.setInteger("filter0", refinery.getFilter(0));
|
||||
// slot.cpt.setInteger("filter1", refinery.getFilter(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,8 +51,8 @@ public class BptBlockRefinery extends BptBlock {
|
|||
filterMeta1 = slot.cpt.getInteger("filterMeta1");
|
||||
}
|
||||
|
||||
refinery.setFilter(0, filter0, filterMeta0);
|
||||
refinery.setFilter(1, filter1, filterMeta1);
|
||||
// refinery.setFilter(0, filter0, filterMeta0);
|
||||
// refinery.setFilter(1, filter1, filterMeta1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import buildcraft.core.EntityBlock;
|
|||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadArrays;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
@ -320,7 +321,7 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
|
|||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(3, 1, 0);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(3, 1, 0);
|
||||
if (tank.getFluid() != null) {
|
||||
payload.intPayload[0] = tank.getFluid().getFluid().getID();
|
||||
payload.intPayload[1] = tank.getFluid().amount;
|
||||
|
@ -336,15 +337,16 @@ public class TilePump extends TileBuildCraft implements IMachine, IPowerReceptor
|
|||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
if (packet.payload.intPayload[0] > 0) {
|
||||
FluidStack liquid = new FluidStack(FluidRegistry.getFluid(packet.payload.intPayload[0]), packet.payload.intPayload[2]);
|
||||
PacketPayloadArrays payload = (PacketPayloadArrays)packet.payload;
|
||||
if (payload.intPayload[0] > 0) {
|
||||
FluidStack liquid = new FluidStack(FluidRegistry.getFluid(payload.intPayload[0]), payload.intPayload[2]);
|
||||
tank.setFluid(liquid);
|
||||
} else {
|
||||
tank.setFluid(null);
|
||||
}
|
||||
|
||||
aimY = packet.payload.intPayload[3];
|
||||
tubeY = packet.payload.floatPayload[0];
|
||||
aimY = payload.intPayload[3];
|
||||
tubeY = payload.floatPayload[0];
|
||||
|
||||
setTubePosition();
|
||||
}
|
||||
|
|
|
@ -14,12 +14,19 @@ import buildcraft.api.power.IPowerReceptor;
|
|||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import buildcraft.api.recipes.RefineryRecipe;
|
||||
import buildcraft.api.recipes.RefineryRecipes;
|
||||
import buildcraft.api.recipes.RefineryRecipes.Recipe;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.liquids.Tank;
|
||||
import buildcraft.core.liquids.TankManager;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadStream;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
|
@ -27,20 +34,21 @@ import net.minecraft.inventory.IInventory;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowerReceptor, IInventory, IMachine {
|
||||
|
||||
private int[] filters = new int[2];
|
||||
private int[] filtersMeta = new int[2];
|
||||
private Fluid[] filters = new Fluid[2];
|
||||
public static int LIQUID_PER_SLOT = FluidContainerRegistry.BUCKET_VOLUME * 4;
|
||||
public FluidTank ingredient1 = new FluidTank(LIQUID_PER_SLOT);
|
||||
public FluidTank ingredient2 = new FluidTank(LIQUID_PER_SLOT);
|
||||
public FluidTank result = new FluidTank(LIQUID_PER_SLOT);
|
||||
public Tank tank1 = new Tank("tank1", LIQUID_PER_SLOT);
|
||||
public Tank tank2 = new Tank("tank2", LIQUID_PER_SLOT);
|
||||
public Tank result = new Tank("result", LIQUID_PER_SLOT);
|
||||
public TankManager tankManager = new TankManager(tank1, tank2, result);
|
||||
public float animationSpeed = 1;
|
||||
private int animationStage = 0;
|
||||
SafeTimeTracker time = new SafeTimeTracker();
|
||||
|
@ -51,11 +59,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
public TileRefinery() {
|
||||
powerHandler = new PowerHandler(this, Type.MACHINE);
|
||||
initPowerProvider();
|
||||
|
||||
filters[0] = 0;
|
||||
filters[1] = 0;
|
||||
filtersMeta[0] = 0;
|
||||
filtersMeta[1] = 0;
|
||||
}
|
||||
|
||||
private void initPowerProvider() {
|
||||
|
@ -128,22 +131,14 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
|
||||
isActive = false;
|
||||
|
||||
RefineryRecipe currentRecipe = null;
|
||||
Recipe currentRecipe = RefineryRecipes.findRefineryRecipe(tank1.getFluid(), tank2.getFluid());
|
||||
|
||||
currentRecipe = RefineryRecipe.findRefineryRecipe(ingredient1.getFluid().getFluid(), ingredient2.getFluid().getFluid());
|
||||
|
||||
FluidStack recipeStack = new FluidStack(currentRecipe.result, amount);
|
||||
if (currentRecipe == null) {
|
||||
decreaseAnimation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.getFluid() != null && result.getFluid().amount != 0 && !result.getFluid().getFluid().equals(currentRecipe.result)) {
|
||||
decreaseAnimation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.fill(currentRecipe.result, false) != currentRecipe.result.amount) {
|
||||
if (result.fill(currentRecipe.result.copy(), false) != currentRecipe.result.amount) {
|
||||
decreaseAnimation();
|
||||
return;
|
||||
}
|
||||
|
@ -173,23 +168,23 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
}
|
||||
}
|
||||
|
||||
private boolean containsInput(FluidStack liquid) {
|
||||
if (liquid == null)
|
||||
private boolean containsInput(FluidStack ingredient) {
|
||||
if (ingredient == null)
|
||||
return true;
|
||||
|
||||
return (ingredient1.getFluid() != null && ingredient1.getFluid().containsFluid(liquid))
|
||||
|| (ingredient2.getFluid() != null && ingredient2.getFluid().containsFluid(liquid));
|
||||
return (tank1.getFluid() != null && tank1.getFluid().containsFluid(ingredient))
|
||||
|| (tank2.getFluid() != null && tank2.getFluid().containsFluid(ingredient));
|
||||
}
|
||||
|
||||
private boolean consumeInput(FluidStack liquid) {
|
||||
if (liquid == null)
|
||||
return true;
|
||||
|
||||
if (ingredient1.getFluid() != null && ingredient1.getFluid().containsFluid(liquid)) {
|
||||
ingredient1.drain(liquid.amount, true);
|
||||
if (tank1.getFluid() != null && tank1.getFluid().containsFluid(liquid)) {
|
||||
tank1.drain(liquid.amount, true);
|
||||
return true;
|
||||
} else if (ingredient2.getFluid() != null && ingredient2.getFluid().containsFluid(liquid)) {
|
||||
ingredient2.drain(liquid.amount, true);
|
||||
} else if (tank2.getFluid() != null && tank2.getFluid().containsFluid(liquid)) {
|
||||
tank2.drain(liquid.amount, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -211,81 +206,34 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
return true;
|
||||
}
|
||||
|
||||
// for compatibility
|
||||
private FluidStack readSlotNBT(NBTTagCompound nbttagcompound) {
|
||||
int liquidId = nbttagcompound.getInteger("liquidId");
|
||||
int quantity = 0;
|
||||
int liquidMeta = 0;
|
||||
|
||||
if (liquidId != 0) {
|
||||
quantity = nbttagcompound.getInteger("quantity");
|
||||
liquidMeta = nbttagcompound.getInteger("liquidMeta");
|
||||
} else {
|
||||
quantity = 0;
|
||||
}
|
||||
|
||||
if (quantity > 0)
|
||||
return new FluidStack(liquidId, quantity, liquidMeta);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
if (nbttagcompound.hasKey("slot1")) {
|
||||
ingredient1.setFluid(readSlotNBT(nbttagcompound.getCompoundTag("slot1")));
|
||||
ingredient2.setFluid(readSlotNBT(nbttagcompound.getCompoundTag("slot2")));
|
||||
result.setFluid(readSlotNBT(nbttagcompound.getCompoundTag("result")));
|
||||
} else {
|
||||
if (nbttagcompound.hasKey("ingredient1")) {
|
||||
ingredient1.setFluid(FluidStack.loadFluidStackFromNBT(nbttagcompound.getCompoundTag("ingredient1")));
|
||||
}
|
||||
if (nbttagcompound.hasKey("ingredient2")) {
|
||||
ingredient2.setFluid(FluidStack.loadFluidStackFromNBT(nbttagcompound.getCompoundTag("ingredient2")));
|
||||
}
|
||||
if (nbttagcompound.hasKey("result")) {
|
||||
result.setFluid(FluidStack.loadFluidStackFromNBT(nbttagcompound.getCompoundTag("result")));
|
||||
}
|
||||
}
|
||||
tankManager.readFromNBT(data);
|
||||
|
||||
animationStage = nbttagcompound.getInteger("animationStage");
|
||||
animationSpeed = nbttagcompound.getFloat("animationSpeed");
|
||||
animationStage = data.getInteger("animationStage");
|
||||
animationSpeed = data.getFloat("animationSpeed");
|
||||
|
||||
powerHandler.readFromNBT(nbttagcompound);
|
||||
powerHandler.readFromNBT(data);
|
||||
initPowerProvider();
|
||||
|
||||
filters[0] = nbttagcompound.getInteger("filters_0");
|
||||
filters[1] = nbttagcompound.getInteger("filters_1");
|
||||
filtersMeta[0] = nbttagcompound.getInteger("filtersMeta_0");
|
||||
filtersMeta[1] = nbttagcompound.getInteger("filtersMeta_1");
|
||||
filters[0] = FluidRegistry.getFluid(data.getString("filter0"));
|
||||
filters[1] = FluidRegistry.getFluid(data.getString("filter1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
if (ingredient1.getFluid() != null) {
|
||||
nbttagcompound.setTag("ingredient1", ingredient1.getFluid().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
tankManager.writeToNBT(data);
|
||||
|
||||
if (ingredient2.getFluid() != null) {
|
||||
nbttagcompound.setTag("ingredient2", ingredient2.getFluid().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
data.setInteger("animationStage", animationStage);
|
||||
data.setFloat("animationSpeed", animationSpeed);
|
||||
powerHandler.writeToNBT(data);
|
||||
|
||||
if (result.getFluid() != null) {
|
||||
nbttagcompound.setTag("result", result.getFluid().writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
nbttagcompound.setInteger("animationStage", animationStage);
|
||||
nbttagcompound.setFloat("animationSpeed", animationSpeed);
|
||||
powerHandler.writeToNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound.setInteger("filters_0", filters[0]);
|
||||
nbttagcompound.setInteger("filters_1", filters[1]);
|
||||
nbttagcompound.setInteger("filtersMeta_0", filtersMeta[0]);
|
||||
nbttagcompound.setInteger("filtersMeta_1", filtersMeta[1]);
|
||||
data.setString("filter0", filters[0].getName());
|
||||
data.setString("filter1", filters[1].getName());
|
||||
}
|
||||
|
||||
public int getAnimationStage() {
|
||||
|
@ -345,47 +293,36 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
public void closeChest() {
|
||||
}
|
||||
|
||||
public void setFilter(int number, int liquidId, int liquidMeta) {
|
||||
filters[number] = liquidId;
|
||||
filtersMeta[number] = liquidMeta;
|
||||
public void setFilter(int number, Fluid fluid) {
|
||||
filters[number] = fluid;
|
||||
}
|
||||
|
||||
public int getFilter(int number) {
|
||||
public Fluid getFilter(int number) {
|
||||
return filters[number];
|
||||
}
|
||||
|
||||
public int getFilterMeta(int number) {
|
||||
return filtersMeta[number];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowAction(IAction action) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
switch (i) {
|
||||
public void getGUINetworkData(int id, int data) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
filters[0] = j;
|
||||
filters[0] = FluidRegistry.getFluid(data);
|
||||
break;
|
||||
case 1:
|
||||
filters[1] = j;
|
||||
break;
|
||||
case 2:
|
||||
filtersMeta[0] = j;
|
||||
break;
|
||||
case 3:
|
||||
filtersMeta[1] = j;
|
||||
filters[1] = FluidRegistry.getFluid(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(container, 0, filters[0]);
|
||||
iCrafting.sendProgressBarUpdate(container, 1, filters[1]);
|
||||
iCrafting.sendProgressBarUpdate(container, 2, filtersMeta[0]);
|
||||
iCrafting.sendProgressBarUpdate(container, 3, filtersMeta[1]);
|
||||
if (filters[0] != null)
|
||||
iCrafting.sendProgressBarUpdate(container, 0, filters[0].getID());
|
||||
if (filters[1] != null)
|
||||
iCrafting.sendProgressBarUpdate(container, 1, filters[1].getID());
|
||||
}
|
||||
|
||||
/* ITANKCONTAINER */
|
||||
|
@ -394,20 +331,20 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
int used = 0;
|
||||
FluidStack resourceUsing = resource.copy();
|
||||
|
||||
if (filters[0] != 0 || filters[1] != 0) {
|
||||
if (filters[0] == resource.itemID && filtersMeta[0] == resource.itemMeta) {
|
||||
used += ingredient1.fill(resourceUsing, doFill);
|
||||
if (filters[0] != null || filters[1] != null) {
|
||||
if (filters[0] == resource.getFluid()) {
|
||||
used += tank1.fill(resourceUsing, doFill);
|
||||
}
|
||||
|
||||
resourceUsing.amount -= used;
|
||||
|
||||
if (filters[1] == resource.itemID && filtersMeta[1] == resource.itemMeta) {
|
||||
used += ingredient2.fill(resourceUsing, doFill);
|
||||
if (filters[1] == resource.getFluid()) {
|
||||
used += tank2.fill(resourceUsing, doFill);
|
||||
}
|
||||
} else {
|
||||
used += ingredient1.fill(resourceUsing, doFill);
|
||||
used += tank1.fill(resourceUsing, doFill);
|
||||
resourceUsing.amount -= used;
|
||||
used += ingredient2.fill(resourceUsing, doFill);
|
||||
used += tank2.fill(resourceUsing, doFill);
|
||||
}
|
||||
|
||||
if (doFill && used > 0) {
|
||||
|
@ -418,138 +355,50 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe
|
|||
return used;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(int tankIndex, FluidStack resource, boolean doFill) {
|
||||
|
||||
if (tankIndex == 0 && resource.itemID == filters[0] && resource.itemMeta == filtersMeta[0])
|
||||
return ingredient1.fill(resource, doFill);
|
||||
if (tankIndex == 1 && resource.itemID == filters[1] && resource.itemMeta == filtersMeta[1])
|
||||
return ingredient2.fill(resource, doFill);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxEmpty, boolean doDrain) {
|
||||
return drain(2, maxEmpty, doDrain);
|
||||
return result.drain(maxEmpty, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(int tankIndex, int maxEmpty, boolean doDrain) {
|
||||
if (tankIndex == 2)
|
||||
return result.drain(maxEmpty, doDrain);
|
||||
|
||||
return null;
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
if (resource == null || !resource.isFluidEqual(result.getFluid()))
|
||||
return null;
|
||||
return drain(from, resource.amount, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidTank[] getTanks(ForgeDirection direction) {
|
||||
return new IFluidTank[]{ingredient1, ingredient2, result};
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidTank getTank(ForgeDirection direction, FluidStack type) {
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
|
||||
|
||||
switch (direction) {
|
||||
case NORTH:
|
||||
switch (dir) {
|
||||
case WEST:
|
||||
return ingredient2;
|
||||
case EAST:
|
||||
return ingredient1;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
case SOUTH:
|
||||
switch (dir) {
|
||||
case WEST:
|
||||
return ingredient1;
|
||||
case EAST:
|
||||
return ingredient2;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
case EAST:
|
||||
switch (dir) {
|
||||
case NORTH:
|
||||
return ingredient2;
|
||||
case SOUTH:
|
||||
return ingredient1;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
case WEST:
|
||||
switch (dir) {
|
||||
case NORTH:
|
||||
return ingredient1;
|
||||
case SOUTH:
|
||||
return ingredient2;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
case DOWN:
|
||||
return result;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection direction) {
|
||||
return tankManager.getTankInfo(direction);
|
||||
}
|
||||
|
||||
// Network
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(9, 1, 0);
|
||||
if (ingredient1.getFluid() != null) {
|
||||
payload.intPayload[0] = ingredient1.getFluid().itemID;
|
||||
payload.intPayload[1] = ingredient1.getFluid().itemMeta;
|
||||
payload.intPayload[2] = ingredient1.getFluid().amount;
|
||||
} else {
|
||||
payload.intPayload[0] = 0;
|
||||
payload.intPayload[1] = 0;
|
||||
payload.intPayload[2] = 0;
|
||||
}
|
||||
if (ingredient2.getFluid() != null) {
|
||||
payload.intPayload[3] = ingredient2.getFluid().itemID;
|
||||
payload.intPayload[4] = ingredient2.getFluid().itemMeta;
|
||||
payload.intPayload[5] = ingredient2.getFluid().amount;
|
||||
} else {
|
||||
payload.intPayload[3] = 0;
|
||||
payload.intPayload[4] = 0;
|
||||
payload.intPayload[5] = 0;
|
||||
}
|
||||
if (result.getFluid() != null) {
|
||||
payload.intPayload[6] = result.getFluid().itemID;
|
||||
payload.intPayload[7] = result.getFluid().itemMeta;
|
||||
payload.intPayload[8] = result.getFluid().amount;
|
||||
} else {
|
||||
payload.intPayload[6] = 0;
|
||||
payload.intPayload[7] = 0;
|
||||
payload.intPayload[8] = 0;
|
||||
}
|
||||
payload.floatPayload[0] = animationSpeed;
|
||||
|
||||
PacketPayload payload = new PacketPayloadStream(new PacketPayloadStream.StreamWriter() {
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeFloat(animationSpeed);
|
||||
tankManager.writeData(data);
|
||||
}
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
if (packet.payload.intPayload[0] > 0) {
|
||||
ingredient1.setFluid(new FluidStack(packet.payload.intPayload[0], packet.payload.intPayload[2], packet.payload.intPayload[1]));
|
||||
} else {
|
||||
ingredient1.setFluid(null);
|
||||
}
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
DataInputStream stream = ((PacketPayloadStream) packet.payload).stream;
|
||||
animationSpeed = stream.readFloat();
|
||||
tankManager.readData(stream);
|
||||
}
|
||||
|
||||
if (packet.payload.intPayload[3] > 0) {
|
||||
ingredient2.setFluid(new FluidStack(packet.payload.intPayload[3], packet.payload.intPayload[5], packet.payload.intPayload[4]));
|
||||
} else {
|
||||
ingredient2.setFluid(null);
|
||||
}
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (packet.payload.intPayload[6] > 0) {
|
||||
result.setFluid(new FluidStack(packet.payload.intPayload[6], packet.payload.intPayload[8], packet.payload.intPayload[7]));
|
||||
} else {
|
||||
result.setFluid(null);
|
||||
}
|
||||
|
||||
animationSpeed = packet.payload.floatPayload[0];
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,15 +10,20 @@ package buildcraft.factory;
|
|||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.liquids.Tank;
|
||||
import buildcraft.core.liquids.TankManager;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadStream;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
@ -26,7 +31,8 @@ import net.minecraftforge.fluids.IFluidHandler;
|
|||
|
||||
public class TileTank extends TileBuildCraft implements IFluidHandler {
|
||||
|
||||
public final FluidTank tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME * 16);
|
||||
public final Tank tank = new Tank("tank", FluidContainerRegistry.BUCKET_VOLUME * 16);
|
||||
public final TankManager tankManager = new TankManager(tank);
|
||||
public boolean hasUpdate = false;
|
||||
public SafeTimeTracker tracker = new SafeTimeTracker();
|
||||
|
||||
|
@ -51,38 +57,32 @@ public class TileTank extends TileBuildCraft implements IFluidHandler {
|
|||
/* NETWORK */
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
if (tank.getFluid() != null) {
|
||||
payload.intPayload[0] = tank.getFluid().getFluid().getID();
|
||||
payload.intPayload[1] = tank.getFluid().amount;
|
||||
} else {
|
||||
payload.intPayload[0] = 0;
|
||||
payload.intPayload[1] = 0;
|
||||
}
|
||||
PacketPayload payload = new PacketPayloadStream(new PacketPayloadStream.StreamWriter() {
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
tankManager.writeData(data);
|
||||
}
|
||||
});
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdatePacket(PacketUpdate packet) {
|
||||
if (packet.payload.intPayload[0] > 0) {
|
||||
FluidStack liquid = new FluidStack(FluidRegistry.getFluid(packet.payload.intPayload[0]), packet.payload.intPayload[2]);
|
||||
tank.setFluid(liquid);
|
||||
} else {
|
||||
tank.setFluid(null);
|
||||
}
|
||||
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
|
||||
DataInputStream stream = ((PacketPayloadStream) packet.payload).stream;
|
||||
tankManager.readData(stream);
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
tank.readFromNBT(data);
|
||||
tankManager.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
tank.writeToNBT(data);
|
||||
tankManager.writeToNBT(data);
|
||||
}
|
||||
|
||||
/* HELPER FUNCTIONS */
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
* Copyright (c) SpaceToad, 2011 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
|
||||
* 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.factory.gui;
|
||||
|
||||
import buildcraft.core.gui.BuildCraftContainer;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadStream;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.factory.TileRefinery;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public class ContainerRefinery extends BuildCraftContainer {
|
||||
|
||||
|
@ -46,29 +48,27 @@ public class ContainerRefinery extends BuildCraftContainer {
|
|||
}
|
||||
|
||||
/* SETTING AND GETTING FILTERS */
|
||||
/**
|
||||
* @param slot
|
||||
* @ param liquidId param liquidMeta (for future use)
|
||||
*/
|
||||
public void setFilter(int slot, int liquidId, int liquidMeta) {
|
||||
public void setFilter(final int slot, final Fluid filter) {
|
||||
|
||||
refinery.setFilter(slot, liquidId, liquidMeta);
|
||||
refinery.setFilter(slot, filter);
|
||||
|
||||
if (CoreProxy.proxy.isRenderWorld(refinery.worldObj)) {
|
||||
PacketPayload payload = new PacketPayload(3, 0, 0);
|
||||
payload.intPayload[0] = slot;
|
||||
payload.intPayload[1] = liquidId;
|
||||
payload.intPayload[2] = liquidMeta;
|
||||
PacketPayloadStream payload = new PacketPayloadStream(new PacketPayloadStream.StreamWriter() {
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeByte(slot);
|
||||
data.writeShort(filter != null ? filter.getID() : -1);
|
||||
}
|
||||
});
|
||||
CoreProxy.proxy.sendToServer(new PacketUpdate(PacketIds.REFINERY_FILTER_SET, refinery.xCoord, refinery.yCoord, refinery.zCoord, payload)
|
||||
.getPacket());
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getFilter(int slot) {
|
||||
int liquidId = refinery.getFilter(slot);
|
||||
int liquidMeta = refinery.getFilterMeta(slot);
|
||||
if (liquidId > 0)
|
||||
return new ItemStack(liquidId, 0, liquidMeta);
|
||||
Fluid filter = refinery.getFilter(slot);
|
||||
if (filter != null)
|
||||
return null; // TODO 1.6: er...what to do with this?
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
package buildcraft.factory.gui;
|
||||
|
||||
import buildcraft.api.recipes.RefineryRecipe;
|
||||
import buildcraft.api.recipes.RefineryRecipes;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.gui.GuiAdvancedInterface;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
@ -108,7 +108,7 @@ public class GuiRefinery extends GuiAdvancedInterface {
|
|||
liquid1 = new FluidStack(filter1.itemID, FluidContainerRegistry.BUCKET_VOLUME, filter1.getItemDamage());
|
||||
}
|
||||
|
||||
RefineryRecipe recipe = RefineryRecipe.findRefineryRecipe(liquid0, liquid1);
|
||||
RefineryRecipes recipe = RefineryRecipes.findRefineryRecipe(liquid0, liquid1);
|
||||
|
||||
if (recipe != null) {
|
||||
((ItemSlot) slots[2]).stack = recipe.result.asItemStack();
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package buildcraft.factory.network;
|
||||
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadStream;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.factory.TileRefinery;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
public class PacketHandlerFactory implements IPacketHandler {
|
||||
|
||||
|
@ -25,10 +29,10 @@ public class PacketHandlerFactory implements IPacketHandler {
|
|||
|
||||
switch (packetID) {
|
||||
|
||||
case PacketIds.REFINERY_FILTER_SET:
|
||||
packetU.readData(data);
|
||||
onRefinerySelect((EntityPlayer) player, packetU);
|
||||
break;
|
||||
case PacketIds.REFINERY_FILTER_SET:
|
||||
packetU.readData(data);
|
||||
onRefinerySelect((EntityPlayer) player, packetU);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,14 +53,14 @@ public class PacketHandlerFactory implements IPacketHandler {
|
|||
return (TileRefinery) tile;
|
||||
}
|
||||
|
||||
private void onRefinerySelect(EntityPlayer playerEntity, PacketUpdate packet) {
|
||||
private void onRefinerySelect(EntityPlayer playerEntity, PacketUpdate packet) throws IOException {
|
||||
|
||||
TileRefinery tile = getRefinery(playerEntity.worldObj, packet.posX, packet.posY, packet.posZ);
|
||||
if (tile == null)
|
||||
return;
|
||||
|
||||
tile.setFilter(packet.payload.intPayload[0], packet.payload.intPayload[1], packet.payload.intPayload[2]);
|
||||
DataInputStream stream = ((PacketPayloadStream)packet.payload).stream;
|
||||
|
||||
tile.setFilter(stream.readByte(), FluidRegistry.getFluid(stream.readShort()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,12 +74,12 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
|
|||
int angle = 0;
|
||||
ModelRenderer theMagnet = magnet[0];
|
||||
if (tile != null) {
|
||||
if (tile.ingredient1.getFluid() != null) {
|
||||
liquid1 = tile.ingredient1.getFluid();
|
||||
if (tile.tank1.getFluid() != null) {
|
||||
liquid1 = tile.tank1.getFluid();
|
||||
}
|
||||
|
||||
if (tile.ingredient2.getFluid() != null) {
|
||||
liquid2 = tile.ingredient2.getFluid();
|
||||
if (tile.tank2.getFluid() != null) {
|
||||
liquid2 = tile.tank2.getFluid();
|
||||
}
|
||||
|
||||
if (tile.result.getFluid() != null) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import buildcraft.BuildCraftTransport;
|
|||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadArrays;
|
||||
import java.util.LinkedList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -67,7 +68,7 @@ public abstract class Gate {
|
|||
|
||||
// / SMP
|
||||
public PacketPayload toPayload() {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(1, 0, 0);
|
||||
payload.intPayload[0] = kind.ordinal();
|
||||
return payload;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
* Copyright (c) SpaceToad, 2011 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
|
||||
* 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.transport.gui;
|
||||
|
||||
import buildcraft.api.core.Position;
|
||||
|
@ -20,6 +18,7 @@ import buildcraft.core.gui.BuildCraftContainer;
|
|||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketPayload;
|
||||
import buildcraft.core.network.PacketPayloadArrays;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.transport.Pipe;
|
||||
|
@ -39,10 +38,8 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
|
||||
IInventory playerIInventory;
|
||||
Pipe pipe;
|
||||
|
||||
private final LinkedList<ITrigger> _potentialTriggers = new LinkedList<ITrigger>();
|
||||
private final LinkedList<IAction> _potentialActions = new LinkedList<IAction>();
|
||||
|
||||
private boolean isSynchronized = false;
|
||||
private boolean isNetInitialized = false;
|
||||
public boolean[] triggerState = new boolean[8];
|
||||
|
@ -84,17 +81,19 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
|
||||
LinkedList<ITrigger> nearbyTriggers = ActionManager.getNeighborTriggers(block, tile);
|
||||
|
||||
for (ITrigger t : nearbyTriggers)
|
||||
for (ITrigger t : nearbyTriggers) {
|
||||
if (!_potentialTriggers.contains(t)) {
|
||||
_potentialTriggers.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList<IAction> nearbyActions = ActionManager.getNeighborActions(block, tile);
|
||||
|
||||
for (IAction a : nearbyActions)
|
||||
for (IAction a : nearbyActions) {
|
||||
if (!_potentialActions.contains(a)) {
|
||||
_potentialActions.add(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,10 +103,12 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
return true;
|
||||
}
|
||||
|
||||
/** CLIENT SIDE **/
|
||||
|
||||
/**
|
||||
* Marks client side gate container as needing to be synchronized with the server.
|
||||
* CLIENT SIDE *
|
||||
*/
|
||||
/**
|
||||
* Marks client side gate container as needing to be synchronized with the
|
||||
* server.
|
||||
*/
|
||||
public void markDirty() {
|
||||
isSynchronized = false;
|
||||
|
@ -121,10 +122,11 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
public void updateActions(PacketUpdate packet) {
|
||||
|
||||
_potentialActions.clear();
|
||||
int length = packet.payload.intPayload[0];
|
||||
PacketPayloadArrays payload = (PacketPayloadArrays) packet.payload;
|
||||
int length = payload.intPayload[0];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
_potentialActions.add(ActionManager.actions[packet.payload.intPayload[i + 1]]);
|
||||
_potentialActions.add(ActionManager.actions[payload.intPayload[i + 1]]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -136,10 +138,11 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
*/
|
||||
public void updateTriggers(PacketUpdate packet) {
|
||||
_potentialTriggers.clear();
|
||||
int length = packet.payload.intPayload[0];
|
||||
PacketPayloadArrays payload = (PacketPayloadArrays) packet.payload;
|
||||
int length = payload.intPayload[0];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
_potentialTriggers.add(ActionManager.triggers[packet.payload.intPayload[i + 1]]);
|
||||
_potentialTriggers.add(ActionManager.triggers[payload.intPayload[i + 1]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +152,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
* @param packet
|
||||
*/
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
PacketPayload payload = packet.payload;
|
||||
PacketPayloadArrays payload = (PacketPayloadArrays) packet.payload;
|
||||
int position = payload.intPayload[0];
|
||||
|
||||
if (payload.intPayload[1] >= 0 && payload.intPayload[1] < ActionManager.triggers.length) {
|
||||
|
@ -182,7 +185,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
}
|
||||
|
||||
public void sendSelectionChange(int position) {
|
||||
PacketPayload payload = new PacketPayload(6, 0, 0);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(6, 0, 0);
|
||||
|
||||
payload.intPayload[0] = position;
|
||||
|
||||
|
@ -208,7 +211,8 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Initializes the list of triggers and actions on the gate and (re-)requests the current selection on the gate if needed.
|
||||
* Initializes the list of triggers and actions on the gate and
|
||||
* (re-)requests the current selection on the gate if needed.
|
||||
*/
|
||||
public void synchronize() {
|
||||
|
||||
|
@ -233,7 +237,9 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
}
|
||||
}
|
||||
|
||||
/** SERVER SIDE **/
|
||||
/**
|
||||
* SERVER SIDE *
|
||||
*/
|
||||
private int calculateTriggerState() {
|
||||
int state = 0;
|
||||
for (int i = 0; i < triggerState.length; i++) {
|
||||
|
@ -266,7 +272,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
}
|
||||
|
||||
public void handleSelectionChange(PacketUpdate packet) {
|
||||
PacketPayload payload = packet.payload;
|
||||
PacketPayloadArrays payload = (PacketPayloadArrays)packet.payload;
|
||||
int position = payload.intPayload[0];
|
||||
|
||||
if (payload.intPayload[1] >= 0 && payload.intPayload[1] < ActionManager.triggers.length) {
|
||||
|
@ -307,7 +313,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
|
||||
// Compose update packet
|
||||
int length = _potentialActions.size();
|
||||
PacketPayload payload = new PacketPayload(length + 1, 0, 0);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(length + 1, 0, 0);
|
||||
|
||||
payload.intPayload[0] = length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
@ -329,7 +335,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
|
||||
// Compose update packet
|
||||
int length = _potentialTriggers.size();
|
||||
PacketPayload payload = new PacketPayload(length + 1, 0, 0);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(length + 1, 0, 0);
|
||||
|
||||
payload.intPayload[0] = length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
@ -352,26 +358,26 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
return;
|
||||
int positions = 0;
|
||||
switch (pipe.gate.kind) {
|
||||
case Single:
|
||||
positions = 1;
|
||||
break;
|
||||
case AND_2:
|
||||
case OR_2:
|
||||
positions = 2;
|
||||
break;
|
||||
case AND_3:
|
||||
case OR_3:
|
||||
positions = 4;
|
||||
break;
|
||||
case OR_4:
|
||||
case AND_4:
|
||||
default:
|
||||
positions = 8;
|
||||
break;
|
||||
case Single:
|
||||
positions = 1;
|
||||
break;
|
||||
case AND_2:
|
||||
case OR_2:
|
||||
positions = 2;
|
||||
break;
|
||||
case AND_3:
|
||||
case OR_3:
|
||||
positions = 4;
|
||||
break;
|
||||
case OR_4:
|
||||
case AND_4:
|
||||
default:
|
||||
positions = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int position = 0; position < positions; position++) {
|
||||
PacketPayload payload = new PacketPayload(6, 0, 0);
|
||||
PacketPayloadArrays payload = new PacketPayloadArrays(6, 0, 0);
|
||||
|
||||
payload.intPayload[0] = position;
|
||||
|
||||
|
@ -399,7 +405,9 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
// System.out.println("Sending current selection to player");
|
||||
}
|
||||
|
||||
/** TRIGGERS **/
|
||||
/**
|
||||
* TRIGGERS *
|
||||
*/
|
||||
public boolean hasTriggers() {
|
||||
return _potentialTriggers.size() > 0;
|
||||
}
|
||||
|
@ -434,7 +442,9 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
}
|
||||
}
|
||||
|
||||
/** ACTIONS **/
|
||||
/**
|
||||
* ACTIONS *
|
||||
*/
|
||||
public boolean hasActions() {
|
||||
return _potentialActions.size() > 0;
|
||||
}
|
||||
|
@ -458,7 +468,9 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
}
|
||||
}
|
||||
|
||||
/** GATE INFORMATION **/
|
||||
/**
|
||||
* GATE INFORMATION *
|
||||
*/
|
||||
public ResourceLocation getGateGuiFile() {
|
||||
return pipe.gate.getGuiFile();
|
||||
}
|
||||
|
@ -470,5 +482,4 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
|||
public String getGateName() {
|
||||
return pipe.gate.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue