improve comparator support
This commit is contained in:
parent
0df6c0963f
commit
a0a81e2503
9 changed files with 83 additions and 9 deletions
|
@ -20,19 +20,24 @@ Improvements:
|
|||
* Minor optimizations (asie, gamerForEA)
|
||||
* Builders:
|
||||
* New blueprint library GUI, now featuring a scrollbar! (asie)
|
||||
* Factory:
|
||||
* Chutes now support the Comparator (asie)
|
||||
* Less lag on Tank updating - new comparator update system (asie)
|
||||
* Robotics:
|
||||
* Zone Planners now have a dynamic texture (asie)
|
||||
* Add events for robot interaction and removal (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.
|
||||
* Builders and requesters now request more than one item at a time.
|
||||
* Zone Planners now have a dynamic texture (asie)
|
||||
* Requesters now support the Comparator (asie)
|
||||
* Add events for robot interaction and removal (asie)
|
||||
* Transport:
|
||||
* Filtered Buffers now support the Comparator (asie)
|
||||
* Lenses do not require Iron Ingots anymore (asie)
|
||||
* New power beam display algorithm (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)
|
||||
* Lenses do not require Iron Ingots anymore (asie)
|
||||
* Fluid pipe capacity and extraction rate now scales with the base flow multiplier. (asie)
|
||||
|
||||
Bugs fixed:
|
||||
|
||||
|
|
|
@ -15,9 +15,11 @@ import net.minecraft.client.renderer.texture.IIconRegister;
|
|||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -26,9 +28,11 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.events.BlockInteractionEvent;
|
||||
import buildcraft.api.tiles.IHasWork;
|
||||
import buildcraft.core.BCCreativeTab;
|
||||
import buildcraft.core.lib.inventory.InventoryIterator;
|
||||
import buildcraft.core.lib.utils.ResourceUtils;
|
||||
import buildcraft.core.lib.utils.Utils;
|
||||
import buildcraft.core.lib.utils.XorShift128Random;
|
||||
|
@ -271,4 +275,32 @@ public abstract class BlockBuildCraft extends BlockContainer {
|
|||
}
|
||||
return meta >= 2 && meta <= 5 ? meta : 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasComparatorInputOverride() {
|
||||
return this instanceof IComparatorInventory;
|
||||
}
|
||||
|
||||
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile instanceof IInventory) {
|
||||
int count = 0;
|
||||
int countNonEmpty = 0;
|
||||
float power = 0.0F;
|
||||
for (IInvSlot slot : InventoryIterator.getIterable((IInventory) tile, ForgeDirection.getOrientation(side))) {
|
||||
if (((IComparatorInventory) this).doesSlotCountComparator(tile, slot.getIndex(), slot.getStackInSlot())) {
|
||||
count++;
|
||||
if (slot.getStackInSlot() != null) {
|
||||
countNonEmpty++;
|
||||
power += (float) slot.getStackInSlot().stackSize / (float) Math.min(((IInventory) tile).getInventoryStackLimit(), slot.getStackInSlot().getMaxStackSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
power /= count;
|
||||
return MathHelper.floor_float(power * 14.0F) + (countNonEmpty > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
11
common/buildcraft/core/lib/block/IComparatorInventory.java
Normal file
11
common/buildcraft/core/lib/block/IComparatorInventory.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package buildcraft.core.lib.block;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* Implemented by Blocks which have an inventory Comparator override.
|
||||
*/
|
||||
public interface IComparatorInventory {
|
||||
boolean doesSlotCountComparator(TileEntity tile, int slot, ItemStack stack);
|
||||
}
|
|
@ -302,6 +302,10 @@ public final class BlockUtils {
|
|||
return done;
|
||||
}
|
||||
|
||||
public static void onComparatorUpdate(World world, int x, int y, int z, Block block) {
|
||||
world.func_147453_f(x, y, z, block);
|
||||
}
|
||||
|
||||
public static TileEntityChest getOtherDoubleChest(TileEntity inv) {
|
||||
if (inv instanceof TileEntityChest) {
|
||||
TileEntityChest chest = (TileEntityChest) inv;
|
||||
|
|
|
@ -11,6 +11,7 @@ package buildcraft.factory;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -22,9 +23,9 @@ import buildcraft.BuildCraftFactory;
|
|||
import buildcraft.api.transport.IItemPipe;
|
||||
import buildcraft.core.GuiIds;
|
||||
import buildcraft.core.lib.block.BlockBuildCraft;
|
||||
import buildcraft.core.lib.block.IComparatorInventory;
|
||||
|
||||
public class BlockHopper extends BlockBuildCraft {
|
||||
|
||||
public class BlockHopper extends BlockBuildCraft implements IComparatorInventory {
|
||||
private static IIcon icon;
|
||||
|
||||
public BlockHopper() {
|
||||
|
@ -85,4 +86,9 @@ public class BlockHopper extends BlockBuildCraft {
|
|||
public IIcon getIconAbsolute(int par1, int par2) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesSlotCountComparator(TileEntity tile, int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ public class TileHopper extends TileBuildCraft implements IInventory, IEnergyHan
|
|||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
super.markDirty();
|
||||
isEmpty = true;
|
||||
|
||||
for (int internalSlot = 0; internalSlot < inventory.getSizeInventory(); internalSlot++) {
|
||||
|
|
|
@ -27,6 +27,7 @@ import buildcraft.api.core.SafeTimeTracker;
|
|||
import buildcraft.core.lib.block.TileBuildCraft;
|
||||
import buildcraft.core.lib.fluids.Tank;
|
||||
import buildcraft.core.lib.fluids.TankManager;
|
||||
import buildcraft.core.lib.utils.BlockUtils;
|
||||
|
||||
public class TileTank extends TileBuildCraft implements IFluidHandler {
|
||||
public final Tank tank = new Tank("tank", FluidContainerRegistry.BUCKET_VOLUME * 16, this);
|
||||
|
@ -82,7 +83,7 @@ public class TileTank extends TileBuildCraft implements IFluidHandler {
|
|||
}
|
||||
|
||||
if (hasUpdate) {
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
|
||||
BlockUtils.onComparatorUpdate(worldObj, xCoord, yCoord, zCoord, getBlockType());
|
||||
hasUpdate = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,14 +10,16 @@ package buildcraft.robotics;
|
|||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.BuildCraftRobotics;
|
||||
import buildcraft.core.GuiIds;
|
||||
import buildcraft.core.lib.block.BlockBuildCraft;
|
||||
import buildcraft.core.lib.block.IComparatorInventory;
|
||||
|
||||
public class BlockRequester extends BlockBuildCraft {
|
||||
public class BlockRequester extends BlockBuildCraft implements IComparatorInventory {
|
||||
public BlockRequester() {
|
||||
super(Material.iron);
|
||||
setRotatable(true);
|
||||
|
@ -42,4 +44,9 @@ public class BlockRequester extends BlockBuildCraft {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesSlotCountComparator(TileEntity tile, int slot, ItemStack stack) {
|
||||
return ((TileRequester) tile).getRequestTemplate(slot) != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ package buildcraft.transport;
|
|||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
@ -17,8 +18,9 @@ import buildcraft.BuildCraftTransport;
|
|||
import buildcraft.api.transport.IItemPipe;
|
||||
import buildcraft.core.GuiIds;
|
||||
import buildcraft.core.lib.block.BlockBuildCraft;
|
||||
import buildcraft.core.lib.block.IComparatorInventory;
|
||||
|
||||
public class BlockFilteredBuffer extends BlockBuildCraft {
|
||||
public class BlockFilteredBuffer extends BlockBuildCraft implements IComparatorInventory {
|
||||
public BlockFilteredBuffer() {
|
||||
super(Material.iron);
|
||||
setHardness(5F);
|
||||
|
@ -52,4 +54,9 @@ public class BlockFilteredBuffer extends BlockBuildCraft {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesSlotCountComparator(TileEntity tile, int slot, ItemStack stack) {
|
||||
return ((TileFilteredBuffer) tile).getFilters().getStackInSlot(slot) != null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue