made progress with builder animation, for #1497

This commit is contained in:
SpaceToad 2014-03-30 18:41:50 +02:00
parent 12138c4d53
commit 573ed26f60
10 changed files with 318 additions and 22 deletions

View file

@ -34,6 +34,7 @@ import buildcraft.builders.BlockBuilder;
import buildcraft.builders.BlockFiller;
import buildcraft.builders.BlockMarker;
import buildcraft.builders.BlockPathMarker;
import buildcraft.builders.BlockStripes;
import buildcraft.builders.BuilderProxy;
import buildcraft.builders.EventHandlerBuilders;
import buildcraft.builders.GuiHandler;
@ -108,6 +109,7 @@ public class BuildCraftBuilders extends BuildCraftMod {
public static final char BPT_SEP_CHARACTER = '-';
public static final int LIBRARY_PAGE_SIZE = 12;
public static final int MAX_BLUEPRINTS_NAME_SIZE = 14;
public static BlockStripes stripesBlock;
public static BlockMarker markerBlock;
public static BlockPathMarker pathMarkerBlock;
public static BlockFiller fillerBlock;
@ -296,6 +298,9 @@ public class BuildCraftBuilders extends BuildCraftMod {
LanguageRegistry.addName(blueprintItem, "Blueprint");
CoreProxy.proxy.registerItem(blueprintItem);
stripesBlock = new BlockStripes ();
CoreProxy.proxy.registerBlock(stripesBlock);
markerBlock = new BlockMarker();
CoreProxy.proxy.registerBlock(markerBlock.setBlockName("markerBlock"));

View file

@ -21,6 +21,10 @@ public class Position {
@NetworkData
public ForgeDirection orientation;
public Position() {
}
public Position(double ci, double cj, double ck) {
x = ci;
y = cj;

View file

@ -0,0 +1,36 @@
/**
* 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 net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockStripes extends Block {
public BlockStripes() {
super(Material.iron);
}
IIcon texture;
@Override
public IIcon getIcon(int i, int j) {
return texture;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister) {
texture = par1IconRegister.registerIcon("buildcraft:blockStripesLaser");
}
}

View file

@ -0,0 +1,121 @@
/**
* 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.Date;
import java.util.LinkedList;
import net.minecraft.item.ItemStack;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.core.Position;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.network.NetworkData;
public class BuildingItem {
@NetworkData
public Position origin, destination;
@NetworkData
public LinkedList <ItemStack> stackToBuild = new LinkedList<ItemStack>();
public Position pos = new Position(),
posDisplay = new Position(),
displayDiff = new Position();
long previousUpdate;
boolean isDone = false;
double lifetime = 0;
double lifetimeDisplay = 0;
double maxLifetime = 0;
private boolean initialized = false;
double vx, vy, vz;
public BuildingSlot slotToBuild;
public IBuilderContext context;
public void initialize () {
if (!initialized) {
double dx = destination.x - origin.x;
double dy = destination.y - origin.y;
double dz = destination.z - origin.z;
double size = Math.sqrt(dx * dx + dy * dy + dz * dz);
maxLifetime = size * 5.0;
vx = dx / maxLifetime;
vy = dy / maxLifetime;
vz = dz / maxLifetime;
pos.x = origin.x;
pos.y = origin.y;
pos.z = origin.z;
initialized = true;
}
}
public void update () {
if (isDone) {
return;
}
initialize();
pos.x += vx;
pos.y += vy;
pos.z += vz;
posDisplay.x = pos.x;
posDisplay.y = pos.y + Math.sin(lifetime / maxLifetime * Math.PI) * 10.0;
posDisplay.z = pos.z;
lifetime++;
if (lifetime > maxLifetime) {
isDone = true;
build ();
}
lifetimeDisplay = lifetime;
displayDiff = new Position(0, 0, 0);
previousUpdate = new Date ().getTime();
}
public void displayUpdate () {
initialize();
double tickDuration = 1000.0 / 20.0;
long currentUpdate = new Date ().getTime();
double timeSpan = currentUpdate - previousUpdate;
previousUpdate = currentUpdate;
double displayPortion = timeSpan / tickDuration;
lifetimeDisplay += 1.0 * displayPortion;
if (lifetimeDisplay - lifetime <= 1.0) {
displayDiff.x += vx * displayPortion;
displayDiff.y += vy * displayPortion;
displayDiff.z += vz * displayPortion;
posDisplay.x = pos.x + displayDiff.x;
posDisplay.y = pos.y + displayDiff.y
+ Math.sin(lifetimeDisplay / maxLifetime * Math.PI) * 10.0;
posDisplay.z = pos.z + displayDiff.z;
}
}
private void build() {
if (slotToBuild != null) {
slotToBuild.writeToWorld(context);
}
}
}

View file

@ -8,11 +8,16 @@
*/
package buildcraft.builders;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import buildcraft.BuildCraftBuilders;
import buildcraft.builders.urbanism.RenderBoxProvider;
import buildcraft.core.EntityLaser;
import buildcraft.core.LaserData;
@ -20,6 +25,24 @@ import buildcraft.core.render.RenderLaser;
public class RenderBuilder extends RenderBoxProvider {
private final EntityItem dummyEntityItem = new EntityItem(null);
private final RenderItem customRenderItem;
public RenderBuilder () {
customRenderItem = new RenderItem() {
@Override
public boolean shouldBob() {
return false;
}
@Override
public boolean shouldSpreadItems() {
return false;
}
};
customRenderItem.setRenderManager(RenderManager.instance);
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
super.renderTileEntityAt(tileentity, x, y, z, f);
@ -52,6 +75,40 @@ public class RenderBuilder extends RenderBoxProvider {
GL11.glPopAttrib();
GL11.glPopMatrix();
}
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
GL11.glTranslated(-tileentity.xCoord, -tileentity.yCoord, -tileentity.zCoord);
for (BuildingItem i : builder.buildingItems) {
doRenderItem(i, 1.0F);
}
GL11.glPopMatrix();
}
public void doRenderItem(BuildingItem i, float light) {
if (i == null) {
return;
}
ItemStack stackToDisplay = i.stackToBuild.getFirst();
if (stackToDisplay == null) {
stackToDisplay = new ItemStack(BuildCraftBuilders.stripesBlock);
}
i.displayUpdate();
float renderScale = 0.7f;
GL11.glPushMatrix();
GL11.glTranslatef((float) i.posDisplay.x, (float) i.posDisplay.y, (float) i.posDisplay.z);
GL11.glTranslatef(0, 0.25F, 0);
GL11.glScalef(renderScale, renderScale, renderScale);
dummyEntityItem.setEntityItemStack(stackToDisplay);
customRenderItem.doRender(dummyEntityItem, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
}
}

View file

@ -69,6 +69,8 @@ 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;
@ -523,6 +525,20 @@ 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;
}
@ -672,10 +688,19 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
BuildingSlot slot = bluePrintBuilder.getNextBlock(worldObj, this);
if (slot != null) {
slot.writeToWorld(bluePrintBuilder.context);
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.stackToBuild = slot.getRequirements(bluePrintBuilder.getContext());
buildingItems.add(i);
RPCHandler.rpcBroadcastPlayers(this, "launchItem", i);
}
if (slot == null || bluePrintBuilder.done) {
// TODO: find a way to confirm that all agents are done before
// calling post processing.
bluePrintBuilder.postProcessing(worldObj);
bluePrintBuilder = null;
@ -710,4 +735,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IM
return null;
}
}
@RPC (RPCSide.CLIENT)
public void launchItem (BuildingItem item) {
buildingItems.add(item);
}
}

View file

@ -10,10 +10,11 @@ package buildcraft.core.blueprints;
import java.util.LinkedList;
import buildcraft.api.blueprints.IBuilderContext;
import net.minecraft.item.ItemStack;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.core.Position;
public class BuildingSlot {
public abstract class BuildingSlot {
public void writeToWorld(IBuilderContext context) {
@ -26,4 +27,6 @@ public class BuildingSlot {
public LinkedList<ItemStack> getRequirements (IBuilderContext context) {
return new LinkedList<ItemStack>();
}
public abstract Position getDestination ();
}

View file

@ -15,6 +15,7 @@ import net.minecraft.tileentity.TileEntity;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.core.Position;
public class BuildingSlotBlock extends BuildingSlot implements Comparable<BuildingSlotBlock> {
@ -71,7 +72,11 @@ public class BuildingSlotBlock extends BuildingSlot implements Comparable<Buildi
@Override
public LinkedList<ItemStack> getRequirements (IBuilderContext context) {
return getSchematic().getRequirements(context);
if (mode == Mode.ClearIfInvalid) {
return new LinkedList<ItemStack>();
} else {
return getSchematic().getRequirements(context);
}
}
@Override
@ -103,4 +108,9 @@ public class BuildingSlotBlock extends BuildingSlot implements Comparable<Buildi
return 0;
}
}
@Override
public Position getDestination () {
return new Position (x + 0.5, y + 0.5, z + 0.5);
}
}

View file

@ -8,9 +8,11 @@
*/
package buildcraft.core.blueprints;
import net.minecraft.nbt.NBTTagList;
import buildcraft.api.blueprints.CoordTransformation;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.core.Position;
public class BuildingSlotEntity extends BuildingSlot {
@ -21,4 +23,14 @@ public class BuildingSlotEntity extends BuildingSlot {
public void writeToWorld(IBuilderContext context) {
schematic.writeToWorld(context, transform);
}
@Override
public Position getDestination () {
NBTTagList nbttaglist = schematic.cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
pos = transform.translate(pos);
return pos;
}
}

View file

@ -206,8 +206,9 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
boolean initialized = false;
private void initializeDisplayPowerList(World world) {
if (initialized)
if (initialized) {
return;
}
initialized = true;
@ -365,47 +366,53 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
boolean center = false;
if (minX == 0 && maxX != 1 && (foundY || foundZ))
if (minX == 0 && maxX != 1 && (foundY || foundZ)) {
if (cx == CoreConstants.PIPE_MIN_POS) {
maxX = CoreConstants.PIPE_MIN_POS;
} else {
center = true;
}
}
if (minX != 0 && maxX == 1 && (foundY || foundZ))
if (minX != 0 && maxX == 1 && (foundY || foundZ)) {
if (cx == CoreConstants.PIPE_MAX_POS) {
minX = CoreConstants.PIPE_MAX_POS;
} else {
center = true;
}
}
if (minY == 0 && maxY != 1 && (foundX || foundZ))
if (minY == 0 && maxY != 1 && (foundX || foundZ)) {
if (cy == CoreConstants.PIPE_MIN_POS) {
maxY = CoreConstants.PIPE_MIN_POS;
} else {
center = true;
}
}
if (minY != 0 && maxY == 1 && (foundX || foundZ))
if (minY != 0 && maxY == 1 && (foundX || foundZ)) {
if (cy == CoreConstants.PIPE_MAX_POS) {
minY = CoreConstants.PIPE_MAX_POS;
} else {
center = true;
}
}
if (minZ == 0 && maxZ != 1 && (foundX || foundY))
if (minZ == 0 && maxZ != 1 && (foundX || foundY)) {
if (cz == CoreConstants.PIPE_MIN_POS) {
maxZ = CoreConstants.PIPE_MIN_POS;
} else {
center = true;
}
}
if (minZ != 0 && maxZ == 1 && (foundX || foundY))
if (minZ != 0 && maxZ == 1 && (foundX || foundY)) {
if (cz == CoreConstants.PIPE_MAX_POS) {
minZ = CoreConstants.PIPE_MAX_POS;
} else {
center = true;
}
}
boolean found = foundX || foundY || foundZ;
@ -481,10 +488,11 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
bindTexture(TextureMap.locationBlocksTexture);
IIcon iconLogic;
if (pipe.renderState.isGateLit())
if (pipe.renderState.isGateLit()) {
iconLogic = pipe.pipe.gate.logic.getIconLit();
else
} else {
iconLogic = pipe.pipe.gate.logic.getIconDark();
}
float translateCenter = 0;
@ -508,8 +516,9 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
}
IIcon materialIcon = pipe.pipe.gate.material.getIconBlock();
if (materialIcon != null)
if (materialIcon != null) {
renderGate(pipe, materialIcon, 1, 0.13F, translateCenter, translateCenter);
}
for (IGateExpansion expansion : pipe.pipe.gate.expansions.keySet()) {
renderGate(pipe, expansion.getOverlayBlock(), 2, 0.13F, translateCenter, translateCenter);
@ -554,8 +563,9 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
float[][] rotated = MatrixTranformations.deepClone(zeroState);
MatrixTranformations.transform(rotated, direction);
if (layer != 0)
if (layer != 0) {
box.setRenderSingleSide(direction.ordinal());
}
box.setBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
RenderEntityBlock.INSTANCE.renderBlock(box, tile.getWorldObj(), 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
GL11.glPopMatrix();
@ -581,13 +591,15 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
connections++;
if (connections == 1)
if (connections == 1) {
targetOrientation = o;
}
}
}
if (connections > 1 || connections == 0)
if (connections > 1 || connections == 0) {
return false;
}
return targetOrientation.getOpposite() == direction;
}
@ -672,8 +684,9 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
}
}
if (!needsRender)
if (!needsRender) {
return;
}
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
@ -693,16 +706,19 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
FluidStack fluidStack = trans.renderCache[i];
if (fluidStack == null || fluidStack.amount <= 0)
if (fluidStack == null || fluidStack.amount <= 0) {
continue;
}
if (!pipe.container.isPipeConnected(side))
if (!pipe.container.isPipeConnected(side)) {
continue;
}
DisplayFluidList d = getListFromBuffer(fluidStack, pipe.container.getWorldObj());
if (d == null)
if (d == null) {
continue;
}
int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
@ -768,8 +784,9 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
int liquidId = stack.fluidID;
if (liquidId == 0)
if (liquidId == 0) {
return null;
}
return getDisplayFluidLists(liquidId, world);
}