improvements to Stripes Pipes

This commit is contained in:
asiekierka 2015-03-20 15:07:12 +01:00
parent fd00ca3138
commit 36ec39a59e
10 changed files with 264 additions and 82 deletions

View file

@ -14,6 +14,10 @@ Additions:
* Light Sensor expansion for detecting brightness in front of a gate (asie) * Light Sensor expansion for detecting brightness in front of a gate (asie)
* Pipes: * Pipes:
* Massive optimizations - up to 3x less server-intensive (asie, Player) * Massive optimizations - up to 3x less server-intensive (asie, Player)
* Improvements to Stripes Pipes:
* Extending or retracting a Stripes Pipe now carries over all its gates, pipe wires and pluggables (asie)
* You can now extend pipe wires by putting them into a Stripes Pipe (asie)
* PlaceBlock now works directly in front of a block again (asie)
* Made items in pipes move at a much smoother rate (asie) * Made items in pipes move at a much smoother rate (asie)
* Robots: * Robots:
* Improved robot light handling - the light now denotes sleep state and battery charge level (asie) * Improved robot light handling - the light now denotes sleep state and battery charge level (asie)

View file

@ -20,7 +20,9 @@ import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.WorldServer;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
@ -29,9 +31,15 @@ import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent; import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Property; import net.minecraftforge.common.config.Property;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.RecipeSorter; import net.minecraftforge.oredict.RecipeSorter;
@ -160,10 +168,12 @@ import buildcraft.transport.statements.TriggerPipeContents;
import buildcraft.transport.statements.TriggerPipeContents.PipeContents; import buildcraft.transport.statements.TriggerPipeContents.PipeContents;
import buildcraft.transport.statements.TriggerPipeSignal; import buildcraft.transport.statements.TriggerPipeSignal;
import buildcraft.transport.statements.TriggerRedstoneFaderInput; import buildcraft.transport.statements.TriggerRedstoneFaderInput;
import buildcraft.transport.stripes.PipeExtensionListener;
import buildcraft.transport.stripes.StripesHandlerArrow; import buildcraft.transport.stripes.StripesHandlerArrow;
import buildcraft.transport.stripes.StripesHandlerBucket; import buildcraft.transport.stripes.StripesHandlerBucket;
import buildcraft.transport.stripes.StripesHandlerEntityInteract; import buildcraft.transport.stripes.StripesHandlerEntityInteract;
import buildcraft.transport.stripes.StripesHandlerHoe; import buildcraft.transport.stripes.StripesHandlerHoe;
import buildcraft.transport.stripes.StripesHandlerPipeWires;
import buildcraft.transport.stripes.StripesHandlerPipes; import buildcraft.transport.stripes.StripesHandlerPipes;
import buildcraft.transport.stripes.StripesHandlerPlaceBlock; import buildcraft.transport.stripes.StripesHandlerPlaceBlock;
import buildcraft.transport.stripes.StripesHandlerRightClick; import buildcraft.transport.stripes.StripesHandlerRightClick;
@ -255,6 +265,8 @@ public class BuildCraftTransport extends BuildCraftMod {
public static float gateCostMultiplier = 1.0F; public static float gateCostMultiplier = 1.0F;
public static PipeExtensionListener pipeExtensionListener;
private static LinkedList<PipeRecipe> pipeRecipes = new LinkedList<PipeRecipe>(); private static LinkedList<PipeRecipe> pipeRecipes = new LinkedList<PipeRecipe>();
private static ChannelHandler transportChannelHandler; private static ChannelHandler transportChannelHandler;
@ -495,6 +507,7 @@ public class BuildCraftTransport extends BuildCraftMod {
PipeManager.registerStripesHandler(new StripesHandlerArrow()); PipeManager.registerStripesHandler(new StripesHandlerArrow());
PipeManager.registerStripesHandler(new StripesHandlerShears()); PipeManager.registerStripesHandler(new StripesHandlerShears());
PipeManager.registerStripesHandler(new StripesHandlerPipes()); PipeManager.registerStripesHandler(new StripesHandlerPipes());
PipeManager.registerStripesHandler(new StripesHandlerPipeWires());
PipeManager.registerStripesHandler(new StripesHandlerEntityInteract()); PipeManager.registerStripesHandler(new StripesHandlerEntityInteract());
PipeManager.registerStripesHandler(new StripesHandlerPlaceBlock()); PipeManager.registerStripesHandler(new StripesHandlerPlaceBlock());
PipeManager.registerStripesHandler(new StripesHandlerHoe()); PipeManager.registerStripesHandler(new StripesHandlerHoe());
@ -541,6 +554,22 @@ public class BuildCraftTransport extends BuildCraftMod {
} }
} }
@Mod.EventHandler
public void serverLoading(FMLServerStartingEvent event) {
pipeExtensionListener = new PipeExtensionListener();
FMLCommonHandler.instance().bus().register(pipeExtensionListener);
}
@Mod.EventHandler
public void serverUnloading(FMLServerStoppingEvent event) {
// One last tick
for (WorldServer w : DimensionManager.getWorlds()) {
pipeExtensionListener.tick(new TickEvent.WorldTickEvent(Side.SERVER, TickEvent.Phase.END, w));
}
FMLCommonHandler.instance().bus().unregister(pipeExtensionListener);
pipeExtensionListener = null;
}
private void postInitSilicon() { private void postInitSilicon() {
Map<IGateExpansion, ItemStack> recipes = GateExpansions.getRecipesForPostInit(); Map<IGateExpansion, ItemStack> recipes = GateExpansions.getRecipesForPostInit();
int recipeId = 0; int recipeId = 0;

View file

@ -150,7 +150,7 @@ public class LibraryDatabase {
LibraryId id = new LibraryId(); LibraryId id = new LibraryId();
int sepIndex = fileName.lastIndexOf(BuildCraftBuilders.BPT_SEP_CHARACTER); int sepIndex = fileName.lastIndexOf(LibraryId.BPT_SEP_CHARACTER);
int dotIndex = fileName.lastIndexOf('.'); int dotIndex = fileName.lastIndexOf('.');
String extension = fileName.substring(dotIndex + 1); String extension = fileName.substring(dotIndex + 1);

View file

@ -28,7 +28,6 @@ import buildcraft.core.Box;
import buildcraft.core.Box.Kind; import buildcraft.core.Box.Kind;
import buildcraft.core.IBoxProvider; import buildcraft.core.IBoxProvider;
import buildcraft.core.LaserData; import buildcraft.core.LaserData;
import buildcraft.core.blueprints.BlueprintUtils;
import buildcraft.core.lib.block.TileBuildCraft; import buildcraft.core.lib.block.TileBuildCraft;
import buildcraft.core.blueprints.Blueprint; import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BlueprintBase; import buildcraft.core.blueprints.BlueprintBase;

View file

@ -982,15 +982,16 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
return; return;
} }
if (pipe == null && coreState.pipeId != 0) {
initialize(BlockGenericPipe.createPipe((Item) Item.itemRegistry.getObjectById(coreState.pipeId)));
}
if (pipe == null) {
return;
}
switch (stateId) { switch (stateId) {
case 0: case 0:
if (pipe == null && coreState.pipeId != 0) {
initialize(BlockGenericPipe.createPipe((Item) Item.itemRegistry.getObjectById(coreState.pipeId)));
}
if (pipe == null) {
break;
}
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord); worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
break; break;

View file

@ -196,7 +196,7 @@ public final class FacadeRenderHelper {
setRenderBounds(renderblocks, rotated, direction); setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z); renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
} }
BlockGenericPipe.facadeRenderColor = -1; ((FakeBlock) blockStateMachine.getBlock()).setColor(0xFFFFFF);
if (renderBlock.getRenderType() == 31) { if (renderBlock.getRenderType() == 31) {
renderblocks.uvRotateSouth = 0; renderblocks.uvRotateSouth = 0;
@ -209,7 +209,7 @@ public final class FacadeRenderHelper {
} }
} }
BlockGenericPipe.facadeRenderColor = -1; ((FakeBlock) blockStateMachine.getBlock()).setColor(0xFFFFFF);
} }
((TextureStateManager) textureManager.getTextureState()).pushArray(); ((TextureStateManager) textureManager.getTextureState()).pushArray();

View file

@ -0,0 +1,149 @@
package buildcraft.transport.stripes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.Position;
import buildcraft.api.transport.IStripesActivator;
import buildcraft.api.transport.IStripesHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.TravelingItem;
import buildcraft.transport.utils.TransportUtils;
/**
* Created by asie on 3/20/15.
*/
public class PipeExtensionListener {
private class PipeExtensionRequest {
public ItemStack stack;
public int x, y, z;
public ForgeDirection o;
public IStripesActivator h;
}
private final Map<World, HashSet<PipeExtensionRequest>> requests = new HashMap<World, HashSet<PipeExtensionRequest>>();
public void requestPipeExtension(ItemStack stack, World world, int x, int y, int z, ForgeDirection o, IStripesActivator h) {
if (world.isRemote) {
return;
}
if (!requests.containsKey(world)) {
requests.put(world, new HashSet<PipeExtensionRequest>());
}
PipeExtensionRequest r = new PipeExtensionRequest();
r.stack = stack;
r.x = x;
r.y = y;
r.z = z;
r.o = o;
r.h = h;
requests.get(world).add(r);
}
@SubscribeEvent
public void tick(TickEvent.WorldTickEvent event) {
if (event.phase == TickEvent.Phase.END && requests.containsKey(event.world)) {
HashSet<PipeExtensionRequest> rSet = requests.get(event.world);
World w = event.world;
for (PipeExtensionRequest r : rSet) {
Position target = new Position(r.x, r.y, r.z);
target.orientation = r.o;
boolean retract = r.stack.getItem() == BuildCraftTransport.pipeItemsVoid;
ArrayList<ItemStack> removedPipeStacks = null;
if (retract) {
target.moveBackwards(1.0D);
} else {
target.moveForwards(1.0D);
if (!w.isAirBlock((int) target.x, (int) target.y, (int) target.z)) {
r.h.sendItem(r.stack, r.o.getOpposite());
continue;
}
}
// Step 1: Copy over and remove existing pipe
Block oldBlock = w.getBlock(r.x, r.y, r.z);
int oldMeta = w.getBlockMetadata(r.x, r.y, r.z);
NBTTagCompound nbt = new NBTTagCompound();
w.getTileEntity(r.x, r.y, r.z).writeToNBT(nbt);
w.setBlockToAir(r.x, r.y, r.z);
// Step 2: If retracting, remove previous pipe; if extending, add new pipe
if (retract) {
removedPipeStacks = w.getBlock((int) target.x, (int) target.y, (int) target.z).getDrops(w, (int) target.x, (int) target.y, (int) target.z,
w.getBlockMetadata((int) target.x, (int) target.y, (int) target.z), 0);
w.setBlockToAir((int) target.x, (int) target.y, (int) target.z);
} else {
r.stack.getItem().onItemUse(r.stack,
CoreProxy.proxy.getBuildCraftPlayer((WorldServer) w, r.x, r.y, r.z).get(),
w, r.x, r.y, r.z, 1, 0, 0, 0);
}
// Step 3: Place stripes pipe back
// - Correct NBT coordinates
nbt.setInteger("x", (int) target.x);
nbt.setInteger("y", (int) target.y);
nbt.setInteger("z", (int) target.z);
// - Create block and tile
TileGenericPipe pipeTile = (TileGenericPipe) TileEntity.createAndLoadEntity(nbt);
w.setBlock((int) target.x, (int) target.y, (int) target.z, oldBlock, oldMeta, 3);
w.setTileEntity((int) target.x, (int) target.y, (int) target.z, pipeTile);
pipeTile.setWorldObj(w);
pipeTile.validate();
pipeTile.updateEntity();
// Step 4: Hope for the best, clean up.
PipeTransportItems items = (PipeTransportItems) pipeTile.pipe.transport;
if (!retract) {
r.stack.stackSize--;
}
if (r.stack.stackSize > 0) {
sendItem(items, r.stack, r.o.getOpposite());
}
if (removedPipeStacks != null) {
for (ItemStack s : removedPipeStacks) {
sendItem(items, s, r.o.getOpposite());
}
}
if (!retract) {
TileGenericPipe newPipeTile = (TileGenericPipe) w.getTileEntity(r.x, r.y, r.z);
newPipeTile.updateEntity();
pipeTile.scheduleNeighborChange();
}
}
rSet.clear();
}
}
private void sendItem(PipeTransportItems transport, ItemStack itemStack, ForgeDirection direction) {
TravelingItem newItem = TravelingItem.make(
transport.container.xCoord + 0.5,
transport.container.yCoord + TransportUtils.getPipeFloorOf(itemStack),
transport.container.zCoord + 0.5, itemStack);
transport.injectItem(newItem, direction);
}
}

View file

@ -0,0 +1,60 @@
package buildcraft.transport.stripes;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.Position;
import buildcraft.api.transport.IStripesActivator;
import buildcraft.api.transport.IStripesHandler;
import buildcraft.transport.ItemPipeWire;
import buildcraft.transport.TileGenericPipe;
public class StripesHandlerPipeWires implements IStripesHandler {
@Override
public StripesHandlerType getType() {
return StripesHandlerType.ITEM_USE;
}
@Override
public boolean shouldHandle(ItemStack stack) {
return (stack.getItem() instanceof ItemPipeWire);
}
@Override
public boolean handle(World world, int x, int y, int z, ForgeDirection direction, ItemStack stack, EntityPlayer player, IStripesActivator activator) {
int pipesToTry = 8;
int pipeWireColor = stack.getItemDamage();
Position p = new Position(x, y, z);
p.orientation = direction;
while (pipesToTry > 0) {
p.moveBackwards(1.0);
TileEntity tile = world.getTileEntity((int) p.x, (int) p.y, (int) p.z);
if (tile instanceof TileGenericPipe) {
TileGenericPipe pipeTile = (TileGenericPipe) tile;
if (!pipeTile.pipe.wireSet[pipeWireColor]) {
pipeTile.pipe.wireSet[pipeWireColor] = true;
pipeTile.pipe.signalStrength[pipeWireColor] = 0;
pipeTile.pipe.updateSignalState();
pipeTile.scheduleRenderUpdate();
world.notifyBlocksOfNeighborChange(pipeTile.xCoord, pipeTile.yCoord, pipeTile.zCoord, pipeTile.getBlock());
return true;
} else {
pipesToTry--;
continue;
}
} else {
// Not a pipe, don't follow chain
break;
}
}
return false;
}
}

View file

@ -8,8 +8,6 @@
*/ */
package buildcraft.transport.stripes; package buildcraft.transport.stripes;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -22,9 +20,7 @@ import buildcraft.BuildCraftTransport;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.api.transport.IStripesActivator; import buildcraft.api.transport.IStripesActivator;
import buildcraft.api.transport.IStripesHandler; import buildcraft.api.transport.IStripesHandler;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.ItemPipe; import buildcraft.transport.ItemPipe;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
@ -49,12 +45,8 @@ public class StripesHandlerPipes implements IStripesHandler {
return false; return false;
} }
if (world.getBlock(x, y, z) != Blocks.air) {
return false;
}
Position p = new Position(x, y, z, direction); Position p = new Position(x, y, z, direction);
p.moveBackwards(1.0d); p.moveBackwards(1.0D);
TileEntity tile = world.getTileEntity((int) p.x, (int) p.y, (int) p.z); TileEntity tile = world.getTileEntity((int) p.x, (int) p.y, (int) p.z);
if (!(tile instanceof TileGenericPipe)) { if (!(tile instanceof TileGenericPipe)) {
@ -64,69 +56,9 @@ public class StripesHandlerPipes implements IStripesHandler {
if (!(pipeTile.pipe.transport instanceof PipeTransportItems)) { if (!(pipeTile.pipe.transport instanceof PipeTransportItems)) {
return false; return false;
} }
// Checks done, start to actually do stuff
if (stack.getItem() != BuildCraftTransport.pipeItemsVoid) { // Checks done, request extension
return extendPipe(world, x, y, z, direction, stack, player, pipeTile); BuildCraftTransport.pipeExtensionListener.requestPipeExtension(stack, world, (int) p.x, (int) p.y, (int) p.z, direction, activator);
} else {
p.moveBackwards(1.0d);
return retractPipe(world, (int) p.x, (int) p.y, (int) p.z, direction, stack, player, pipeTile);
}
}
private boolean extendPipe(World world, int x, int y, int z, ForgeDirection direction, ItemStack stack, EntityPlayer player,
TileGenericPipe pipeTile) {
if (!copyPipeTo(world, pipeTile, x, y, z, player)) {
return false;
}
pipeTile.initializeFromItemMetadata(stack.getItemDamage());
Pipe<?> newPipe = BlockGenericPipe.createPipe(stack.getItem());
newPipe.setTile(pipeTile);
pipeTile.pipe = newPipe;
pipeTile.updateEntity(); // Needed so that the tile does computeConnections()
stack.stackSize--;
if (stack.stackSize > 0) {
pipeTile.injectItem(stack, true, direction.getOpposite());
}
return true;
}
private boolean copyPipeTo(World world, TileGenericPipe pipeTile, int x, int y, int z, EntityPlayer player) {
int meta = pipeTile.pipe.container.getItemMetadata();
ItemStack stack = new ItemStack(BuildCraftTransport.pipeItemsStripes, 1, meta);
if (!BuildCraftTransport.pipeItemsStripes.onItemUse(stack, player, world, x, y, z, 1, 0, 0, 0)) {
return false;
}
return true;
}
private boolean retractPipe(World world, int x, int y, int z, ForgeDirection direction, ItemStack stack, EntityPlayer player,
TileGenericPipe pipeTile) {
TileEntity prevTile = world.getTileEntity(x, y, z);
if (!(prevTile instanceof TileGenericPipe)) {
return false;
}
TileGenericPipe prevPipeTile = (TileGenericPipe) prevTile;
if (!(prevPipeTile.pipe.transport instanceof PipeTransportItems)) {
return false;
}
int meta = prevPipeTile.getItemMetadata();
ArrayList<ItemStack> removedPipeStacks = world.getBlock(x, y, z).getDrops(world, x, y, z, meta, 0);
prevPipeTile.initializeFromItemMetadata(pipeTile.getItemMetadata());
Pipe<?> newPipe = BlockGenericPipe.createPipe(BuildCraftTransport.pipeItemsStripes);
newPipe.setTile(prevPipeTile);
prevPipeTile.pipe = newPipe;
world.setBlockToAir(pipeTile.x(), pipeTile.y(), pipeTile.z());
prevPipeTile.injectItem(stack, true, direction);
for (ItemStack itemStack : removedPipeStacks) {
prevPipeTile.injectItem(itemStack, true, direction);
}
return true; return true;
} }
} }

View file

@ -15,6 +15,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.Position;
import buildcraft.api.transport.IStripesActivator; import buildcraft.api.transport.IStripesActivator;
import buildcraft.api.transport.IStripesHandler; import buildcraft.api.transport.IStripesHandler;
@ -36,6 +37,13 @@ public class StripesHandlerPlaceBlock implements IStripesHandler {
IStripesActivator activator) { IStripesActivator activator) {
if (!world.isAirBlock(x, y, z) && stack.tryPlaceItemIntoWorld(player, world, x, y, z, 1, 0.0f, 0.0f, 0.0f)) { if (!world.isAirBlock(x, y, z) && stack.tryPlaceItemIntoWorld(player, world, x, y, z, 1, 0.0f, 0.0f, 0.0f)) {
return true; return true;
} else if (world.isAirBlock(x, y, z)) {
Position src = new Position(x, y, z);
src.orientation = direction;
src.moveBackwards(1.0D);
if (stack.tryPlaceItemIntoWorld(player, world, (int) src.x, (int) src.y, (int) src.z, direction.ordinal(), 0.0f, 0.0f, 0.0f)) {
return true;
}
} }
return false; return false;
} }