add base code for dual-mode Architect Table, fix robots (and add safeguard for missing AI constructors), rewrite power beam calculation, add list tooltip code

This commit is contained in:
Adrian 2015-07-19 11:52:40 +02:00
parent 147ba92595
commit 29c90c77b9
15 changed files with 163 additions and 70 deletions

View file

@ -477,6 +477,8 @@ tip.deprecated=Deprecated
tip.filler.excavate.on=Excavate
tip.filler.excavate.off=Do Not Excavate
tip.list.matches=Matches
tip.shift.PipeFluidsDiamond=GUI accepts any fluid containers
tip.shift.PipeFluidsEmerald=GUI accepts any fluid container
tip.shift.PipeItemsClay=Prioritizes machines and chests\nover neighbouring pipes.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 B

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

View file

@ -8,16 +8,18 @@ Additions:
* Clay fluid pipe! The power of insertion applied to liquids. (asie)
* Power Adapters! Connect Kinesis Pipes to non-Kinesis pipes. (asie)
* New blueprint library GUI, now featuring a scrollbar! (asie)
* New Lists - sort by type, material, or both, and other improvements! (asie)
* New Lists! (asie)
* Sort by type, material, or both! Precise sorting!
* See with a tooltip if an item matches the List!
Improvements:
* New power beam display algorithm (asie)
* Use integrated server data in singleplayer for certain tiles - back to the smoothness of 1.2.5! (asie)
* Rewritten pipe wires - should now propagate more or less instantly. (asie)
* Fluid pipe capacity and extraction rate now scales with the base flow multiplier. (asie)
* Debugger support for fluid pipes (asie)
* Add events for robot interaction and removal (asie)
* Tweaked power beam rendering algorithm (asie)
* Rewritten robots request system (hea3ven)
* Changed the IRequestProvider api to be independent of robots.
* Delivery robots can now carry more than an item at a time.

View file

@ -133,6 +133,7 @@ import buildcraft.core.list.ListMatchHandlerClass;
import buildcraft.core.list.ListMatchHandlerFluid;
import buildcraft.core.list.ListMatchHandlerOreDictionary;
import buildcraft.core.list.ListRegistry;
import buildcraft.core.list.ListTooltipHandler;
import buildcraft.core.network.PacketHandlerCore;
import buildcraft.core.properties.WorldPropertyIsDirt;
import buildcraft.core.properties.WorldPropertyIsFarmland;
@ -382,6 +383,7 @@ public class BuildCraftCore extends BuildCraftMod {
FMLCommonHandler.instance().bus().register(this);
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new BlockHighlightHandler());
MinecraftForge.EVENT_BUS.register(new ListTooltipHandler());
}
@Mod.EventHandler

View file

@ -12,18 +12,16 @@ import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
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.core.GuiIds;
import buildcraft.core.internal.ICustomLEDBlock;
import buildcraft.core.lib.block.BlockBuildCraft;
public class BlockArchitect extends BlockBuildCraft {
private IIcon[] led;
public class BlockArchitect extends BlockBuildCraft implements ICustomLEDBlock {
public BlockArchitect() {
super(Material.iron);
setRotatable(true);
@ -68,4 +66,9 @@ public class BlockArchitect extends BlockBuildCraft {
public int getLightValue(IBlockAccess world, int x, int y, int z) {
return 1;
}
@Override
public String[] getLEDSuffixes() {
return new String[] { "led_red", "led_mode_copy", "led_mode_edit" };
}
}

View file

@ -9,7 +9,6 @@
package buildcraft.builders;
import java.util.ArrayList;
import java.util.LinkedList;
import io.netty.buffer.ByteBuf;
@ -44,20 +43,23 @@ import buildcraft.core.lib.utils.NetworkUtils;
import buildcraft.core.lib.utils.Utils;
public class TileArchitect extends TileBuildCraft implements IInventory, IBoxProvider, ICommandReceiver, ILEDProvider {
public enum Mode {
EDIT, COPY
}
public String currentAuthorName = "";
public Mode mode = Mode.EDIT;
public Box box = new Box();
public String name = "";
public BlueprintReadConfiguration readConfiguration = new BlueprintReadConfiguration();
public LinkedList<LaserData> subLasers = new LinkedList<LaserData>();
public ArrayList<LaserData> subLasers = new ArrayList<LaserData>();
public ArrayList<BlockIndex> subBlueprints = new ArrayList<BlockIndex>();
private SimpleInventory inv = new SimpleInventory(2, "Architect", 1);
private RecursiveBlueprintReader reader;
private boolean isProcessing;
private boolean clientIsWorking, initialized;
public TileArchitect() {
box.kind = Kind.BLUE_STRIPES;
@ -68,12 +70,11 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
super.updateEntity();
if (!worldObj.isRemote) {
if (reader != null) {
if (mode == Mode.COPY && reader != null) {
reader.iterate();
if (reader.isDone()) {
reader = null;
isProcessing = false;
sendNetworkUpdate();
}
}
@ -84,17 +85,25 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
public void initialize() {
super.initialize();
if (!worldObj.isRemote) {
if (!worldObj.isRemote && !initialized) {
if (!box.isInitialized()) {
IAreaProvider a = Utils.getNearbyAreaProvider(worldObj, xCoord,
yCoord, zCoord);
if (a != null) {
mode = Mode.COPY;
box.initialize(a);
a.removeFromWorld();
sendNetworkUpdate();
return;
} else {
mode = Mode.EDIT;
}
} else {
mode = Mode.COPY;
}
initialized = true;
sendNetworkUpdate();
}
}
@ -113,7 +122,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
ItemStack result = inv.decrStackSize(i, j);
if (i == 0) {
initializeComputing();
initializeBlueprint();
}
return result;
@ -124,7 +133,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
inv.setInventorySlotContents(i, itemstack);
if (i == 0) {
initializeComputing();
initializeBlueprint();
}
}
@ -158,6 +167,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
inv.readFromNBT(nbt);
mode = Mode.values()[nbt.getByte("mode")];
name = nbt.getString("name");
currentAuthorName = nbt.getString("lastAuthor");
@ -186,6 +196,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
inv.writeToNBT(nbt);
nbt.setByte("mode", (byte) mode.ordinal());
nbt.setString("name", name);
nbt.setString("lastAuthor", currentAuthorName);
@ -204,15 +215,22 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
nbt.setTag("subBlueprints", subBptList);
}
private boolean getIsWorking() {
return mode == Mode.COPY ? reader != null : false;
}
@Override
public void writeData(ByteBuf stream) {
box.writeData(stream);
NetworkUtils.writeUTF(stream, name);
readConfiguration.writeData(stream);
stream.writeBoolean(reader != null);
stream.writeShort(subLasers.size());
for (LaserData ld: subLasers) {
ld.writeData(stream);
stream.writeBoolean(getIsWorking());
stream.writeByte(mode.ordinal());
if (mode == Mode.COPY) {
readConfiguration.writeData(stream);
stream.writeShort(subLasers.size());
for (LaserData ld: subLasers) {
ld.writeData(stream);
}
}
}
@ -220,19 +238,18 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
public void readData(ByteBuf stream) {
box.readData(stream);
name = NetworkUtils.readUTF(stream);
readConfiguration.readData(stream);
boolean newIsProcessing = stream.readBoolean();
if (newIsProcessing != isProcessing) {
isProcessing = newIsProcessing;
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
}
clientIsWorking = stream.readBoolean();
mode = Mode.values()[stream.readByte()];
int size = stream.readUnsignedShort();
subLasers.clear();
for (int i = 0; i < size; i++) {
LaserData ld = new LaserData();
ld.readData(stream);
subLasers.add(ld);
if (mode == Mode.COPY) {
readConfiguration.readData(stream);
int size = stream.readUnsignedShort();
subLasers.clear();
for (int i = 0; i < size; i++) {
LaserData ld = new LaserData();
ld.readData(stream);
subLasers.add(ld);
}
}
}
@Override
@ -241,12 +258,14 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
destroy();
}
private void initializeComputing() {
private void initializeBlueprint() {
if (getWorldObj().isRemote) {
return;
}
reader = new RecursiveBlueprintReader(this);
if (mode == Mode.COPY) {
reader = new RecursiveBlueprintReader(this);
}
sendNetworkUpdate();
}
@ -299,6 +318,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
}
});
}
@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
if ("setName".equals(command)) {
@ -325,9 +345,10 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
}
public void addSubBlueprint(TileEntity sub) {
addSubBlueprint(new BlockIndex(sub));
sendNetworkUpdate();
if (mode == Mode.COPY) {
addSubBlueprint(new BlockIndex(sub));
sendNetworkUpdate();
}
}
private void addSubBlueprint(BlockIndex index) {
@ -348,6 +369,18 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
@Override
public int getLEDLevel(int led) {
return (led == 0 ? isProcessing : box != null && box.isInitialized()) ? 15 : 0;
boolean condition = false;
switch (led) {
case 0:
condition = clientIsWorking;
break;
case 1:
condition = mode == Mode.COPY && box != null && box.isInitialized();
break;
case 2:
condition = mode == Mode.EDIT;
break;
}
return condition ? 15 : 0;
}
}

View file

@ -0,0 +1,5 @@
package buildcraft.core.internal;
public interface ICustomLEDBlock {
String[] getLEDSuffixes();
}

View file

@ -15,6 +15,10 @@ public class AverageInt {
public AverageInt(int precise) {
this.precise = precise;
clear();
}
public void clear() {
this.data = new int[precise];
this.pos = 0;
}

View file

@ -2,18 +2,18 @@ package buildcraft.core.list;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.core.lib.inventory.StackHelper;
import buildcraft.core.lib.utils.FluidUtils;
public class ListMatchHandlerFluid extends ListMatchHandler {
@Override
public boolean matches(Type type, ItemStack stack, ItemStack target, boolean precise) {
if (type == Type.MATERIAL) {
if (type == Type.TYPE) {
if (FluidContainerRegistry.isContainer(stack) && FluidContainerRegistry.isContainer(target)) {
ItemStack emptyContainerStack = FluidContainerRegistry.drainFluidContainer(stack);
ItemStack emptyContainerTarget = FluidContainerRegistry.drainFluidContainer(target);
@ -21,7 +21,7 @@ public class ListMatchHandlerFluid extends ListMatchHandler {
return true;
}
}
} else if (type == Type.TYPE) {
} else if (type == Type.MATERIAL) {
FluidStack fStack = FluidUtils.getFluidStackFromItemStack(stack);
FluidStack fTarget = FluidUtils.getFluidStackFromItemStack(target);
if (fStack != null && fTarget != null) {
@ -33,7 +33,7 @@ public class ListMatchHandlerFluid extends ListMatchHandler {
@Override
public List<ItemStack> getClientExamples(Type type, ItemStack stack) {
if (type == Type.TYPE) {
if (type == Type.MATERIAL) {
FluidStack fStack = FluidUtils.getFluidStackFromItemStack(stack);
if (fStack != null) {
List<ItemStack> examples = new ArrayList<ItemStack>();
@ -44,7 +44,7 @@ public class ListMatchHandlerFluid extends ListMatchHandler {
}
return examples;
}
} else if (type == Type.MATERIAL) {
} else if (type == Type.TYPE) {
if (FluidContainerRegistry.isContainer(stack)) {
List<ItemStack> examples = new ArrayList<ItemStack>();
ItemStack emptyContainerStack = FluidContainerRegistry.drainFluidContainer(stack);

View file

@ -0,0 +1,23 @@
package buildcraft.core.list;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import buildcraft.api.items.IList;
import buildcraft.core.lib.utils.StringUtils;
public class ListTooltipHandler {
@SubscribeEvent
public void itemTooltipEvent(ItemTooltipEvent event) {
if (event.entityPlayer.openContainer instanceof ContainerListNew) {
ItemStack list = event.entityPlayer.getCurrentEquippedItem();
if (list != null && list.getItem() instanceof IList) {
if (((IList) list.getItem()).matches(list, event.itemStack)) {
event.toolTip.add(EnumChatFormatting.GREEN + StringUtils.localize("tip.list.matches"));
}
}
}
}
}

View file

@ -1,6 +1,8 @@
package buildcraft.core.render;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lwjgl.opengl.GL11;
@ -12,6 +14,7 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import buildcraft.core.internal.ICustomLEDBlock;
import buildcraft.core.internal.ILEDProvider;
import buildcraft.core.lib.block.BlockBuildCraft;
import buildcraft.core.lib.render.RenderEntityBlock;
@ -29,12 +32,18 @@ public class RenderLEDTile extends TileEntitySpecialRenderer {
public static void registerBlockIcons(IIconRegister register) {
for (Block b : iconMap.keySet().toArray(new Block[iconMap.keySet().size()])) {
// TODO (7.1): The count of icons is hardcoded here. Consider adding a better way.
String base = ResourceUtils.getObjectPrefix(Block.blockRegistry.getNameForObject(b));
iconMap.put(b, new IIcon[] {
register.registerIcon(base + "/led_red"),
register.registerIcon(base + "/led_green")
});
List<IIcon> icons = new ArrayList<IIcon>();
if (b instanceof ICustomLEDBlock) {
for (String s : ((ICustomLEDBlock) b).getLEDSuffixes()) {
icons.add(register.registerIcon(base + "/" + s));
}
} else {
icons.add(register.registerIcon(base + "/led_red"));
icons.add(register.registerIcon(base + "/led_green"));
}
iconMap.put(b, icons.toArray(new IIcon[icons.size()]));
}
}
@ -58,8 +67,10 @@ public class RenderLEDTile extends TileEntitySpecialRenderer {
GL11.glScalef(Z_OFFSET, Z_OFFSET, Z_OFFSET);
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
for (int i = 0; i < 2; i++) {
renderBox.texture = iconMap.get(block)[i];
IIcon[] icons = iconMap.get(block);
for (int i = 0; i < icons.length; i++) {
renderBox.texture = icons[i];
if (((BlockBuildCraft) block).isRotatable()) {
renderBox.setRenderSingleSide(((BlockBuildCraft) block).getFrontSide(tile.getBlockMetadata()));
} else {
@ -71,7 +82,9 @@ public class RenderLEDTile extends TileEntitySpecialRenderer {
renderBox.renderSide[5] = true;
}
renderBox.light = provider.getLEDLevel(i);
RenderEntityBlock.INSTANCE.renderBlock(renderBox);
if (renderBox.light > 0) {
RenderEntityBlock.INSTANCE.renderBlock(renderBox);
}
}
GL11.glPopAttrib();

View file

@ -28,6 +28,15 @@ public class AIRobotSearchBlock extends AIRobot {
private double maxDistanceToEnd;
private IZone zone;
public AIRobotSearchBlock(EntityRobotBase iRobot) {
super(iRobot);
zone = iRobot.getZoneToWork();
blockFound = null;
pathFound = null;
path = null;
}
public AIRobotSearchBlock(EntityRobotBase iRobot, boolean random, IBlockFilter iPathFound,
double iMaxDistanceToEnd) {
super(iRobot);

View file

@ -32,6 +32,7 @@ import buildcraft.api.transport.IPipeTile;
import buildcraft.core.CompatHooks;
import buildcraft.core.DefaultProps;
import buildcraft.core.lib.block.TileBuildCraft;
import buildcraft.core.lib.utils.AverageInt;
import buildcraft.transport.network.PacketPowerUpdate;
import buildcraft.transport.pipes.PipePowerCobblestone;
import buildcraft.transport.pipes.PipePowerDiamond;
@ -46,8 +47,7 @@ import buildcraft.transport.pipes.PipePowerWood;
public class PipeTransportPower extends PipeTransport implements IDebuggable {
public static final Map<Class<? extends Pipe<?>>, Integer> powerCapacities = new HashMap<Class<? extends Pipe<?>>, Integer>();
public static final Map<Class<? extends Pipe<?>>, Float> powerResistances = new HashMap<Class<? extends Pipe<?>>, Float>();
private static final int DISPLAY_SMOOTHING = 10;
private static final int OVERLOAD_TICKS = 60;
public short[] displayPower = new short[6];
@ -61,13 +61,12 @@ public class PipeTransportPower extends PipeTransport implements IDebuggable {
public int[] dbgEnergyOutput = new int[6];
public int[] dbgEnergyOffered = new int[6];
private final AverageInt[] powerAverage = new AverageInt[6];
private final TileEntity[] tiles = new TileEntity[6];
private final Object[] providers = new Object[6];
private boolean needsInit = true;
private short[] prevDisplayPower = new short[6];
private int[] powerQuery = new int[6];
private long currentDate;
@ -78,6 +77,7 @@ public class PipeTransportPower extends PipeTransport implements IDebuggable {
public PipeTransportPower() {
for (int i = 0; i < 6; ++i) {
powerQuery[i] = 0;
powerAverage[i] = new AverageInt(10);
}
}
@ -159,7 +159,7 @@ public class PipeTransportPower extends PipeTransport implements IDebuggable {
tiles[o] = null;
internalPower[o] = 0;
internalNextPower[o] = 0;
displayPower[o] = 0;
powerAverage[o].clear();
}
providers[o] = getEnergyProvider(o);
}
@ -200,10 +200,6 @@ public class PipeTransportPower extends PipeTransport implements IDebuggable {
}
}
// Send the power to nearby pipes who requested it
System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6);
Arrays.fill(displayPower, (short) 0);
for (int i = 0; i < 6; ++i) {
if (internalPower[i] > 0) {
int totalPowerQuery = 0;
@ -251,16 +247,17 @@ public class PipeTransportPower extends PipeTransport implements IDebuggable {
}
}
displayPower[j] += watts;
displayPower[i] += watts;
powerAverage[j].push((int) Math.ceil(watts));
powerAverage[i].push((int) Math.ceil(watts));
}
}
}
}
}
float highestPower = 0.0F;
short highestPower = 0;
for (int i = 0; i < 6; i++) {
displayPower[i] = (short) Math.ceil((float) (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1) + displayPower[i]) / DISPLAY_SMOOTHING);
powerAverage[i].tick();
displayPower[i] = (short) Math.round(powerAverage[i].getAverage());
if (displayPower[i] > highestPower) {
highestPower = displayPower[i];
}

View file

@ -111,16 +111,16 @@ public class TriggerPipeContents extends BCStatement implements ITriggerInternal
switch (kind) {
case empty:
for (double s : transportPower.displayPower) {
if (s > 1e-4) {
for (short s : transportPower.displayPower) {
if (s > 0) {
return false;
}
}
return true;
case containsEnergy:
for (double s : transportPower.displayPower) {
if (s > 1e-4) {
for (short s : transportPower.displayPower) {
if (s > 0) {
return true;
}
}