mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 10:34:40 +00:00
update
This commit is contained in:
1 parent
fd6eb37369
commit
ce1ac164dc
26 files changed
+912
-43
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package com.glodblock.github.common.block;
|
||||
|
||||
import appeng.block.AEBaseItemBlock;
|
||||
import com.glodblock.github.common.tabs.FluidCraftingTabs;
|
||||
import com.glodblock.github.common.tile.TileLevelMaintainer;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
import com.glodblock.github.inventory.gui.GuiType;
|
||||
import com.glodblock.github.util.BlockPos;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockLevelMaintainer extends FCBaseBlock {
|
||||
|
||||
public BlockLevelMaintainer() {
|
||||
super(Material.iron, NameConst.BLOCK_LEVEL_MAINTAINER);
|
||||
setFullBlock(true);
|
||||
setOpaque(true);
|
||||
setTileEntity(TileLevelMaintainer.class);
|
||||
}
|
||||
|
||||
public BlockLevelMaintainer register() {
|
||||
GameRegistry.registerBlock(this, AEBaseItemBlock.class, NameConst.BLOCK_LEVEL_MAINTAINER);
|
||||
GameRegistry.registerTileEntity(TileLevelMaintainer.class, NameConst.BLOCK_LEVEL_MAINTAINER);
|
||||
setCreativeTab(FluidCraftingTabs.INSTANCE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivated(World world, int x, int y, int z, EntityPlayer player, int facing, float hitX, float hitY, float hitZ) {
|
||||
if (player.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
TileLevelMaintainer tile = getTileEntity(world, x, y, z);
|
||||
if (tile != null) {
|
||||
if (!world.isRemote) {
|
||||
InventoryHandler.openGui(player, world, new BlockPos(x, y, z), EnumFacing.getFront(facing), GuiType.LEVEL_MAINTAINER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ItemStack stack(int size) {
|
||||
return new ItemStack(this, size);
|
||||
}
|
||||
|
||||
public ItemStack stack() {
|
||||
return new ItemStack(this, 1);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public class FluidCellInventory implements IFluidCellInventory {
|
||||
private short storedFluids;
|
||||
private IItemList<IAEFluidStack> cellItems;
|
||||
private final NBTTagCompound tagCompound;
|
||||
public static final int singleByteAmount = 256 * 8;
|
||||
|
||||
public FluidCellInventory( final ItemStack o, final ISaveProvider container ) throws AppEngException {
|
||||
|
||||
@@ -147,8 +148,8 @@ public class FluidCellInventory implements IFluidCellInventory {
|
||||
|
||||
@Override
|
||||
public long getUsedBytes() {
|
||||
long bytesForItemCount = (this.getStoredFluidCount() + this.getUnusedFluidCount()) / (8 * 256);
|
||||
long tmp = this.getStoredFluidTypes() * this.getBytesPerType() + bytesForItemCount;
|
||||
long bytesForItemCount = this.getStoredFluidCount() / singleByteAmount;
|
||||
long tmp = (this.getStoredFluidTypes() * this.getBytesPerType()) * singleByteAmount + bytesForItemCount;
|
||||
if (this.getUnusedFluidCount() > 0 && tmp < this.getTotalBytes()) tmp++;
|
||||
return tmp;
|
||||
}
|
||||
@@ -177,20 +178,14 @@ public class FluidCellInventory implements IFluidCellInventory {
|
||||
|
||||
@Override
|
||||
public long getRemainingFluidCount() {
|
||||
final long remaining = (this.getTotalBytes() - (this.getTotalFluidTypes() * 8)) * 8 * 256 - this.getStoredFluidCount();
|
||||
final long remaining = this.getTotalBytes() * singleByteAmount - this.getStoredFluidCount();
|
||||
return remaining > 0 ? remaining : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnusedFluidCount() {
|
||||
final int div = (int) ( this.getStoredFluidCount() % 8 );
|
||||
return (int) (this.getStoredFluidCount() % singleByteAmount);
|
||||
|
||||
if( div == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 8 - div;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -349,7 +344,7 @@ public class FluidCellInventory implements IFluidCellInventory {
|
||||
|
||||
if( l != null )
|
||||
{
|
||||
final long remainingItemSlots = this.getRemainingFluidCount();
|
||||
final long remainingItemSlots = this.getRemainingFluidCount() - (long) this.getBytesPerType() * singleByteAmount;
|
||||
|
||||
if( remainingItemSlots < 0 )
|
||||
{
|
||||
@@ -384,7 +379,7 @@ public class FluidCellInventory implements IFluidCellInventory {
|
||||
|
||||
if( this.canHoldNewFluid() ) // room for new type, and for at least one item!
|
||||
{
|
||||
final long remainingItemCount = this.getRemainingFluidCount() - this.getBytesPerType() * 8;
|
||||
final long remainingItemCount = this.getRemainingFluidCount() - ((long) this.getBytesPerType() * singleByteAmount);
|
||||
|
||||
if( remainingItemCount > 0 )
|
||||
{
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
package com.glodblock.github.common.tile;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingJob;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.storage.IStackWatcher;
|
||||
import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.helpers.MultiCraftingTracker;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import com.glodblock.github.inventory.AeStackInventory;
|
||||
import com.glodblock.github.inventory.AeStackInventoryImpl;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class TileLevelMaintainer extends AENetworkTile implements IAEAppEngInventory, IStackWatcherHost, IGridTickable, ICraftingRequester {
|
||||
|
||||
public static final int REQ_COUNT = 5;
|
||||
public final InventoryRequest requests = new InventoryRequest(this);
|
||||
private final BaseActionSource source;
|
||||
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker(this, REQ_COUNT);
|
||||
|
||||
|
||||
public TileLevelMaintainer() {
|
||||
getProxy().setIdlePowerUsage(1D);
|
||||
getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getCraftingSlots() {
|
||||
return requests.getCraftingSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return this.craftingTracker.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange(ICraftingLink link) {
|
||||
this.craftingTracker.jobStateChange(link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(5, 120, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
private TickRateModulation doWork() {
|
||||
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
boolean didSomething = false;
|
||||
try {
|
||||
ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
IGrid grid = this.getProxy().getGrid();
|
||||
final IItemList<IAEItemStack> inv = this.getProxy().getStorage().getItemInventory().getStorageList();
|
||||
for (int i = 0; i < REQ_COUNT; i++) {
|
||||
IAEItemStack is = requests.getQuantity(i);
|
||||
if (is != null && requests.getBatchSize(i) > 0) {
|
||||
IAEItemStack craftItem = requests.getCraftItem(i);
|
||||
if (inv.findPrecise(is) == null || inv.findPrecise(is).getStackSize() >= is.getStackSize() || cg.isRequesting(craftItem))
|
||||
continue;
|
||||
|
||||
// do crafting
|
||||
|
||||
Future<ICraftingJob> jobTask = requests.getJobs()[i];
|
||||
|
||||
if (jobTask == null) {
|
||||
requests.getJobs()[i] = cg.beginCraftingJob(getWorldObj(), grid, this.source, craftItem, null);
|
||||
} else if (jobTask.isDone()) {
|
||||
try {
|
||||
ICraftingJob job = jobTask.get();
|
||||
if (job != null) {
|
||||
ICraftingLink link = cg.submitJob(job, null, null, false, this.source);
|
||||
didSomething = true;
|
||||
requests.jobs[i] = null;
|
||||
if (link != null) {
|
||||
requests.links[i] = link;
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges() {
|
||||
super.saveChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack) {
|
||||
try {
|
||||
getProxy().getTick().alertDevice(getProxy().getNode());
|
||||
} catch (GridAccessException e) {
|
||||
// NO-OP
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(IStackWatcher newWatcher) {
|
||||
|
||||
}
|
||||
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange(IItemList o, IAEStack fullStack, IAEStack diffStack, BaseActionSource src, StorageChannel chan) {
|
||||
}
|
||||
|
||||
public InventoryRequest getRequestInventory() {
|
||||
return this.requests;
|
||||
}
|
||||
|
||||
public IInventory getInventory() {
|
||||
return (IInventory) this.requests.getCraftingSlots();
|
||||
}
|
||||
|
||||
public void updateQuantity(int idx, long size) {
|
||||
this.requests.updateQuantity(idx, size);
|
||||
}
|
||||
|
||||
public void updateBatchSize(int idx, long size) {
|
||||
this.requests.updateBatchSize(idx, size);
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public NBTTagCompound writeToNBTEvent(NBTTagCompound data) {
|
||||
this.requests.crafting.writeToNbt(data, "Inventory");
|
||||
this.requests.batchSize.writeToNbt(data, "BatchSize");
|
||||
return data;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBTEvent(NBTTagCompound data) {
|
||||
this.requests.crafting.readFromNbt(data, "Inventory");
|
||||
this.requests.batchSize.readFromNbt(data, "BatchSize");
|
||||
}
|
||||
|
||||
public static class InventoryRequest {
|
||||
private final AeStackInventoryImpl<IAEItemStack> crafting;
|
||||
private final AeStackInventoryImpl<IAEItemStack> batchSize;
|
||||
private Future<ICraftingJob>[] jobs;
|
||||
private ICraftingLink[] links;
|
||||
|
||||
public InventoryRequest(TileLevelMaintainer tile) {
|
||||
this.crafting = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
|
||||
this.batchSize = new AeStackInventoryImpl<>(StorageChannel.ITEMS, REQ_COUNT, tile);
|
||||
this.jobs = new Future[REQ_COUNT];
|
||||
this.links = new ICraftingLink[REQ_COUNT];
|
||||
}
|
||||
|
||||
public Future<ICraftingJob>[] getJobs() {
|
||||
return jobs;
|
||||
}
|
||||
|
||||
public ICraftingLink[] getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getBatchInputs() {
|
||||
return this.batchSize;
|
||||
}
|
||||
|
||||
public AeStackInventory<IAEItemStack> getCraftingSlots() {
|
||||
return this.crafting;
|
||||
}
|
||||
|
||||
public void updateQuantity(int idx, long size) {
|
||||
IAEItemStack is = this.crafting.getStack(idx);
|
||||
if (is != null) {
|
||||
is.setStackSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateBatchSize(int idx, long size) {
|
||||
IAEItemStack is = this.crafting.getStack(idx);
|
||||
if (is != null) {
|
||||
IAEItemStack i = is.copy();
|
||||
i.setStackSize(size);
|
||||
this.batchSize.setStack(idx, i);
|
||||
}
|
||||
}
|
||||
|
||||
public IAEItemStack getQuantity(int idx) {
|
||||
return this.crafting.getStack(idx);
|
||||
}
|
||||
|
||||
public long getBatchSize(int idx) {
|
||||
IAEItemStack is = this.crafting.getStack(idx);
|
||||
IAEItemStack is1 = this.batchSize.getStack(idx);
|
||||
if (is != null && is1 != null && is.isSameType(is1)) {
|
||||
return is1.getStackSize();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IAEItemStack getCraftItem(int idx) {
|
||||
IAEItemStack is = this.crafting.getStack(idx);
|
||||
if (is != null) {
|
||||
IAEItemStack ias = is.copy();
|
||||
ias.setStackSize(this.getBatchSize(idx));
|
||||
return ias;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user