facorised animation code, close #1497

This commit is contained in:
SpaceToad 2014-03-31 23:20:45 +02:00
parent d00dcf0314
commit 9001521647
13 changed files with 193 additions and 119 deletions

View file

@ -8,7 +8,10 @@
*/
package buildcraft.api.blueprints;
import java.util.LinkedList;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import buildcraft.core.utils.BlockUtil;
public class SchematicMask extends Schematic {
@ -37,4 +40,10 @@ public class SchematicMask extends Schematic {
}
}
// TODO: To be removed with the "real" list of items
@Override
public void addRequirements(IBuilderContext context, LinkedList<ItemStack> requirements) {
requirements.add(new ItemStack(Blocks.brick_block));
}
}

View file

@ -17,6 +17,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.core.CreativeTabBuildCraft;
@ -104,4 +105,19 @@ public class BlockFiller extends BlockContainer {
textureTopOff = par1IconRegister.registerIcon("buildcraft:blockFillerTopOff");
textureSides = par1IconRegister.registerIcon("buildcraft:blockFillerSides");
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
@Override
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
return false;
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
return 1;
}
}

View file

@ -23,7 +23,7 @@ public class BuilderProxyClient extends BuilderProxy {
super.registerBlockRenderers();
ClientRegistry.bindTileEntitySpecialRenderer(TileArchitect.class, new RenderBoxProvider());
ClientRegistry.bindTileEntitySpecialRenderer(TileFiller.class, new RenderBoxProvider());
ClientRegistry.bindTileEntitySpecialRenderer(TileFiller.class, new RenderBuilder());
ClientRegistry.bindTileEntitySpecialRenderer(TileBuilder.class, new RenderBuilder());
ClientRegistry.bindTileEntitySpecialRenderer(TilePathMarker.class, new RenderPathMarker());
}

View file

@ -35,9 +35,9 @@ public class BuildingItem implements IBuilder {
}
public Position posDisplay = new Position();
public boolean isDone = false;
long previousUpdate;
boolean isDone = false;
double lifetime = 0;
double lifetimeDisplay = 0;
double maxLifetime = 0;
@ -55,7 +55,7 @@ public class BuildingItem implements IBuilder {
double size = Math.sqrt(dx * dx + dy * dy + dz * dz);
maxLifetime = size * 10.0;
maxLifetime = size * 7.0;
vx = dx / maxLifetime;
vy = dy / maxLifetime;

View file

@ -46,7 +46,7 @@ public class RenderBuilder extends RenderBoxProvider {
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
super.renderTileEntityAt(tileentity, x, y, z, f);
TileBuilder builder = (TileBuilder) tileentity;
TileAbstractBuilder builder = (TileAbstractBuilder) tileentity;
if (builder != null) {
GL11.glPushMatrix();
@ -59,14 +59,16 @@ public class RenderBuilder extends RenderBoxProvider {
GL11.glTranslated(x, y, z);
GL11.glTranslated(-tileentity.xCoord, -tileentity.yCoord, -tileentity.zCoord);
for (LaserData laser : builder.pathLasers) {
if (laser != null) {
GL11.glPushMatrix();
RenderLaser
.doRenderLaser(
TileEntityRendererDispatcher.instance.field_147553_e,
laser, EntityLaser.LASER_TEXTURES[4]);
GL11.glPopMatrix();
if (builder.getPathLaser() != null) {
for (LaserData laser : builder.getPathLaser()) {
if (laser != null) {
GL11.glPushMatrix();
RenderLaser
.doRenderLaser(
TileEntityRendererDispatcher.instance.field_147553_e,
laser, EntityLaser.LASER_TEXTURES[4]);
GL11.glPopMatrix();
}
}
}
@ -80,8 +82,10 @@ public class RenderBuilder extends RenderBoxProvider {
GL11.glTranslated(x, y, z);
GL11.glTranslated(-tileentity.xCoord, -tileentity.yCoord, -tileentity.zCoord);
for (BuildingItem i : builder.buildingItems) {
doRenderItem(i, 1.0F);
if (builder.getBuilders() != null) {
for (BuildingItem i : builder.getBuilders()) {
doRenderItem(i, 1.0F);
}
}
GL11.glPopMatrix();

View file

@ -0,0 +1,68 @@
/**
* 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.builders;
import java.util.ArrayList;
import java.util.LinkedList;
import net.minecraft.inventory.IInventory;
import buildcraft.core.LaserData;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.network.NetworkData;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCSide;
public abstract class TileAbstractBuilder extends TileBuildCraft implements IInventory {
@NetworkData
public LinkedList<LaserData> pathLasers = new LinkedList<LaserData> ();
public ArrayList <BuildingItem> buildersInAction = new ArrayList<BuildingItem>();
@Override
public void updateEntity() {
super.updateEntity();
BuildingItem toRemove = null;
for (BuildingItem i : buildersInAction) {
i.update();
if (i.isDone) {
toRemove = i;
}
}
if (toRemove != null) {
buildersInAction.remove(toRemove);
}
}
public ArrayList<BuildingItem> getBuilders() {
return buildersInAction;
}
public LinkedList<LaserData> getPathLaser() {
return pathLasers;
}
@RPC (RPCSide.CLIENT)
public void launchItem (BuildingItem item) {
buildersInAction.add(item);
}
public void addBuildingItem(BuildingItem item) {
buildersInAction.add(item);
RPCHandler.rpcBroadcastPlayers(this, "launchItem", item);
}
public abstract boolean isBuildingMaterialSlot(int i);
}

View file

@ -28,17 +28,14 @@ import buildcraft.core.BlockIndex;
import buildcraft.core.Box;
import buildcraft.core.Box.Kind;
import buildcraft.core.IBoxProvider;
import buildcraft.core.IBuilderInventory;
import buildcraft.core.IMachine;
import buildcraft.core.LaserData;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BlueprintBase;
import buildcraft.core.blueprints.BptBuilderBase;
import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.network.NetworkData;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
@ -46,7 +43,7 @@ import buildcraft.core.network.RPCSide;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.utils.Utils;
public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IMachine, IBoxProvider {
public class TileBuilder extends TileAbstractBuilder implements IMachine, IBoxProvider {
private final ItemStack items[] = new ItemStack[28];
@ -57,9 +54,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
private LinkedList<BlockIndex> path;
@NetworkData
public LinkedList<LaserData> pathLasers = new LinkedList<LaserData> ();
private EntityRobot builderRobot;
private LinkedList <ItemStack> requiredToBuild;
@ -69,8 +63,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
@MjBattery (maxReceivedPerCycle = 25)
private double mjStored = 0;
public LinkedList <BuildingItem> buildingItems = new LinkedList<BuildingItem>();
private class PathIterator {
public Iterator<BlockIndex> currentIterator;
@ -325,7 +317,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
return;
}
if (bluePrintBuilder == null || bluePrintBuilder.isDone()) {
if (bluePrintBuilder == null || bluePrintBuilder.isDone(this)) {
if (path != null && path.size() > 1) {
if (currentPathIterator == null) {
Iterator<BlockIndex> it = path.iterator();
@ -357,7 +349,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
done = true;
}
} else {
if (bluePrintBuilder != null && bluePrintBuilder.isDone()) {
if (bluePrintBuilder != null && bluePrintBuilder.isDone(this)) {
if (builderRobot != null) {
//builderRobot.markEndOfBlueprint(bluePrintBuilder);
}
@ -525,29 +517,15 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
public void updateEntity() {
super.updateEntity();
BuildingItem toRemove = null;
for (BuildingItem i : buildingItems) {
i.update();
if (i.isDone) {
toRemove = i;
}
}
if (toRemove != null) {
buildingItems.remove(toRemove);
}
if (worldObj.isRemote) {
return;
}
if (bluePrintBuilder != null) {
bluePrintBuilder.removeDoneBuilders();
bluePrintBuilder.removeDoneBuilders(this);
}
if ((bluePrintBuilder == null || bluePrintBuilder.isDone())
if ((bluePrintBuilder == null || bluePrintBuilder.isDone(this))
&& box.isInitialized()
//&& (builderRobot == null || builderRobot.done())
) {
@ -647,7 +625,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
}
@Override
public boolean isBuildingMaterial(int i) {
public boolean isBuildingMaterialSlot(int i) {
return i != 0;
}
@ -689,23 +667,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
}
if (bluePrintBuilder != null) {
BuildingSlot slot = bluePrintBuilder.getNextBlock(worldObj, this);
bluePrintBuilder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
if (slot != null) {
BuildingItem i = new BuildingItem();
i.origin = new Position (xCoord + 0.5, yCoord + 0.5, zCoord + 0.5);
i.destination = slot.getDestination();
i.slotToBuild = slot;
i.context = bluePrintBuilder.getContext();
i.stacksToBuild = slot.getRequirements(bluePrintBuilder.getContext());
buildingItems.add(i);
RPCHandler.rpcBroadcastPlayers(this, "launchItem", i);
bluePrintBuilder.registerBuilder(i);
}
if (bluePrintBuilder.isDone()) {
// TODO: find a way to confirm that all agents are done before
// calling post processing.
if (bluePrintBuilder.isDone(this)) {
bluePrintBuilder.postProcessing(worldObj);
bluePrintBuilder = null;
@ -741,9 +705,4 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
}
}
@RPC (RPCSide.CLIENT)
public void launchItem (BuildingItem item) {
buildingItems.add(item);
}
}

View file

@ -26,13 +26,11 @@ import buildcraft.api.mj.MjBattery;
import buildcraft.builders.filler.pattern.PatternFill;
import buildcraft.builders.triggers.ActionFiller;
import buildcraft.core.Box;
import buildcraft.core.Box.Kind;
import buildcraft.core.IBoxProvider;
import buildcraft.core.IBuilderInventory;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
@ -43,7 +41,7 @@ import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.triggers.ActionMachineControl.Mode;
import buildcraft.core.utils.Utils;
public class TileFiller extends TileBuildCraft implements IBuilderInventory, IMachine, IActionReceptor, IBoxProvider {
public class TileFiller extends TileAbstractBuilder implements IMachine, IActionReceptor, IBoxProvider {
public IFillerPattern currentPattern = PatternFill.INSTANCE;
@ -61,6 +59,7 @@ public class TileFiller extends TileBuildCraft implements IBuilderInventory, IMa
public TileFiller() {
inv.addListener(this);
box.kind = Kind.STRIPES;
}
@Override
@ -118,14 +117,11 @@ public class TileFiller extends TileBuildCraft implements IBuilderInventory, IMa
}
if (currentTemplate != null) {
BuildingSlot s = currentTemplate.getNextBlock(getWorld(), this);
currentTemplate.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
if (s != null) {
s.writeToWorld(context);
}
if (!done && s == null || currentTemplate.isDone()) {
if (currentTemplate.isDone(this)) {
done = true;
currentTemplate = null;
sendNetworkUpdate();
}
}
@ -232,7 +228,9 @@ public class TileFiller extends TileBuildCraft implements IBuilderInventory, IMa
if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
return false;
}
return entityplayer.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64D;
return entityplayer.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D,
zCoord + 0.5D) <= 64D;
}
@Override
@ -355,7 +353,8 @@ public class TileFiller extends TileBuildCraft implements IBuilderInventory, IMa
}
@Override
public boolean isBuildingMaterial(int i) {
public boolean isBuildingMaterialSlot(int i) {
return true;
}
}

View file

@ -1,17 +0,0 @@
/**
* 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;
import net.minecraft.inventory.IInventory;
public interface IBuilderInventory extends IInventory {
public boolean isBuildingMaterial(int i);
}

View file

@ -13,8 +13,10 @@ import java.util.ArrayList;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.Position;
import buildcraft.builders.BuildingItem;
import buildcraft.builders.TileAbstractBuilder;
import buildcraft.core.Box;
import buildcraft.core.IBuilderInventory;
public abstract class BptBuilderBase implements IAreaProvider {
@ -23,8 +25,6 @@ public abstract class BptBuilderBase implements IAreaProvider {
protected boolean done;
public BptContext context;
private ArrayList <IBuilder> buildersInAction = new ArrayList<IBuilder>();
public BptBuilderBase(BlueprintBase bluePrint, World world, int x, int y, int z) {
this.blueprint = bluePrint;
this.x = x;
@ -38,7 +38,25 @@ public abstract class BptBuilderBase implements IAreaProvider {
context = bluePrint.getContext(world, box);
}
public abstract BuildingSlot getNextBlock(World world, IBuilderInventory inv);
public abstract BuildingSlot getNextBlock(World world, TileAbstractBuilder inv);
public boolean buildNextSlot (World world, TileAbstractBuilder builder, int x, int y, int z) {
BuildingSlot slot = getNextBlock(world, builder);
if (slot != null) {
BuildingItem i = new BuildingItem();
i.origin = new Position (x + 0.5, y + 0.5, z + 0.5);
i.destination = slot.getDestination();
i.slotToBuild = slot;
i.context = getContext();
i.stacksToBuild = slot.getRequirements(getContext());
builder.addBuildingItem(i);
return true;
}
return false;
}
@Override
public int xMin() {
@ -87,19 +105,17 @@ public abstract class BptBuilderBase implements IAreaProvider {
return context;
}
public void registerBuilder (IBuilder builder) {
buildersInAction.add(builder);
}
public void removeDoneBuilders (TileAbstractBuilder builder) {
ArrayList<BuildingItem> items = builder.getBuilders();
public void removeDoneBuilders () {
for (int i = buildersInAction.size() - 1; i >= 0; --i) {
if (buildersInAction.get(i).isDone()) {
buildersInAction.remove(i);
for (int i = items.size() - 1; i >= 0; --i) {
if (items.get(i).isDone()) {
items.remove(i);
}
}
}
public boolean isDone () {
return done && buildersInAction.size() == 0;
public boolean isDone (TileAbstractBuilder builder) {
return done && builder.getBuilders().size() == 0;
}
}

View file

@ -24,7 +24,7 @@ import buildcraft.api.blueprints.CoordTransformation;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.core.StackKey;
import buildcraft.core.IBuilderInventory;
import buildcraft.builders.TileAbstractBuilder;
import buildcraft.core.blueprints.BuildingSlotBlock.Mode;
import buildcraft.core.utils.BCLog;
import buildcraft.core.utils.BlockUtil;
@ -127,7 +127,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
}
@Override
public BuildingSlot getNextBlock(World world, IBuilderInventory inv) {
public BuildingSlot getNextBlock(World world, TileAbstractBuilder inv) {
if (clearList.size() != 0) {
BuildingSlot slot = internalGetNextBlock(world, inv, clearList);
checkDone();
@ -160,7 +160,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
return null;
}
private BuildingSlot internalGetNextBlock(World world, IBuilderInventory inv, LinkedList<BuildingSlotBlock> list) {
private BuildingSlot internalGetNextBlock(World world, TileAbstractBuilder inv, LinkedList<BuildingSlotBlock> list) {
LinkedList<BuildingSlotBlock> failSlots = new LinkedList<BuildingSlotBlock>();
BuildingSlot result = null;
@ -209,7 +209,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
return result;
}
public boolean checkRequirements(IBuilderInventory inv, SchematicBlock slot) {
public boolean checkRequirements(TileAbstractBuilder inv, SchematicBlock slot) {
if (slot.block == null) {
return true;
}
@ -231,7 +231,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
int size = inv.getSizeInventory();
for (int i = 0; i < size; ++i) {
if (!inv.isBuildingMaterial(i)) {
if (!inv.isBuildingMaterialSlot(i)) {
continue;
}
@ -270,7 +270,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
return true;
}
public void useRequirements(IBuilderInventory inv, SchematicBlock slot) {
public void useRequirements(TileAbstractBuilder inv, SchematicBlock slot) {
if (slot.block == null) {
return;
}
@ -298,7 +298,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
ItemStack usedStack = reqStk;
int size = inv.getSizeInventory();
for (int i = 0; i < size; ++i) {
if (!inv.isBuildingMaterial(i)) {
if (!inv.isBuildingMaterialSlot(i)) {
}

View file

@ -13,7 +13,7 @@ import java.util.LinkedList;
import net.minecraft.world.World;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.core.IBuilderInventory;
import buildcraft.builders.TileAbstractBuilder;
import buildcraft.core.blueprints.BuildingSlotBlock.Mode;
public class BptBuilderTemplate extends BptBuilderBase {
@ -83,7 +83,7 @@ public class BptBuilderTemplate extends BptBuilderBase {
}
@Override
public BuildingSlot getNextBlock(World world, IBuilderInventory inv) {
public BuildingSlot getNextBlock(World world, TileAbstractBuilder inv) {
if (clearList.size() != 0) {
BuildingSlotBlock slot = internalGetNextBlock(world, inv, clearList);
checkDone();
@ -107,7 +107,7 @@ public class BptBuilderTemplate extends BptBuilderBase {
return null;
}
public BuildingSlotBlock internalGetNextBlock(World world, IBuilderInventory inv, LinkedList<BuildingSlotBlock> list) {
public BuildingSlotBlock internalGetNextBlock(World world, TileAbstractBuilder inv, LinkedList<BuildingSlotBlock> list) {
BuildingSlotBlock result = null;
while (list.size() > 0) {

View file

@ -8,6 +8,7 @@
*/
package buildcraft.factory;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@ -32,12 +33,13 @@ import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.builders.BuildingItem;
import buildcraft.builders.TileAbstractBuilder;
import buildcraft.core.Box;
import buildcraft.core.CoreConstants;
import buildcraft.core.DefaultAreaProvider;
import buildcraft.core.IBuilderInventory;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.LaserData;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BuildingSlot;
@ -51,7 +53,7 @@ import buildcraft.core.utils.Utils;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
public class TileQuarry extends TileBuildCraft implements IMachine, IPowerReceptor, IBuilderInventory {
public class TileQuarry extends TileAbstractBuilder implements IMachine, IPowerReceptor {
public @NetworkData
Box box = new Box();
@ -758,7 +760,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
}
@Override
public boolean isBuildingMaterial(int i) {
public boolean isBuildingMaterialSlot(int i) {
return true;
}
@ -872,4 +874,22 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void addBuildingItem(BuildingItem item) {
// TODO Auto-generated method stub
}
@Override
public ArrayList<BuildingItem> getBuilders() {
// TODO Auto-generated method stub
return null;
}
@Override
public LinkedList<LaserData> getPathLaser() {
// TODO Auto-generated method stub
return null;
}
}