mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-23 13:30:04 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2df9beb31 | ||
|
|
dab5a0dbf3 | ||
|
|
6090f198e6 | ||
|
|
c29f8cf846 | ||
|
|
77ec41812d | ||
|
|
258465a654 | ||
|
|
adbc077736 | ||
|
|
adf317d6a1 | ||
|
|
508f6e5d64 | ||
|
|
c174db3f15 | ||
|
|
e1b3f20078 | ||
|
|
54781c290e | ||
|
|
9c2ef02383 |
No files matched your search
+16
-16
@@ -1,27 +1,27 @@
|
||||
// Add your dependencies here
|
||||
|
||||
dependencies {
|
||||
api('com.github.GTNewHorizons:NotEnoughItems:2.3.39-GTNH:dev')
|
||||
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-180-GTNH:dev')
|
||||
api('com.github.GTNewHorizons:NotEnoughItems:2.3.45-GTNH:dev')
|
||||
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-195-GTNH:dev')
|
||||
api('curse.maven:cofh-core-69162:2388751')
|
||||
api('com.github.GTNewHorizons:waila:1.5.22:dev')
|
||||
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.32:dev') { transitive = false }
|
||||
compileOnly("com.github.GTNewHorizons:WirelessCraftingTerminal:1.8.9.3:dev")
|
||||
api('com.github.GTNewHorizons:waila:1.5.24:dev')
|
||||
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.33:dev') { transitive = false }
|
||||
compileOnly("com.github.GTNewHorizons:WirelessCraftingTerminal:1.9.0:dev")
|
||||
|
||||
compileOnly('com.github.GTNewHorizons:ForestryMC:4.5.6:dev')
|
||||
compileOnly('com.github.GTNewHorizons:EnderIO:2.3.1.49:dev')
|
||||
compileOnly('com.github.GTNewHorizons:EnderCore:0.2.11:dev')
|
||||
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.41.216:dev')
|
||||
compileOnly('com.github.GTNewHorizons:StructureLib:1.2.0-beta.2:dev')
|
||||
compileOnly('com.github.GTNewHorizons:EnderIO:2.4.11:dev')
|
||||
compileOnly('com.github.GTNewHorizons:EnderCore:0.2.13:dev')
|
||||
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.42.82:dev')
|
||||
compileOnly('com.github.GTNewHorizons:StructureLib:1.2.6:dev')
|
||||
compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')
|
||||
compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
|
||||
compileOnly('com.github.GTNewHorizons:AppleCore:3.2.5:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.28:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:AppleCore:3.2.10:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.33:dev') { transitive = false }
|
||||
compileOnly('com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:OpenComputers:1.8.0.5-GTNH:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.3.27-GTNH:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:GTplusplus:1.7.191:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:OpenComputers:1.9.1-GTNH:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.4.1-GTNH:dev') { transitive = false }
|
||||
compileOnly('com.github.GTNewHorizons:GTplusplus:1.8.42:dev') { transitive = false }
|
||||
|
||||
compileOnly('com.github.GTNewHorizons:KekzTech:0.6.25:dev')
|
||||
api('com.github.GTNewHorizons:Baubles:1.0.1.14:dev')
|
||||
compileOnly('com.github.GTNewHorizons:KekzTech:0.7.8:dev')
|
||||
api('com.github.GTNewHorizons:Baubles:1.0.1.16:dev')
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import appeng.api.AEApi;
|
||||
|
||||
import com.glodblock.github.common.Config;
|
||||
import com.glodblock.github.common.storage.FluidCellHandler;
|
||||
import com.glodblock.github.crossmod.extracells.EC2Replacer;
|
||||
import com.glodblock.github.crossmod.opencomputers.OCDriverInit;
|
||||
import com.glodblock.github.crossmod.waila.WailaInit;
|
||||
import com.glodblock.github.inventory.InventoryHandler;
|
||||
@@ -93,6 +94,13 @@ public class FluidCraft {
|
||||
SPacketMEUpdateBuffer.disable();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void missingMappings(FMLMissingMappingsEvent event) {
|
||||
if (!ModAndClassUtil.EC2 && Config.replaceEC2) {
|
||||
EC2Replacer.replaceExtraCells(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onLoadComplete(FMLLoadCompleteEvent event) {}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ public class GuiFluidPatternEncoder extends AEBaseGui {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
protected void renderToolTip(ItemStack stack, int x, int y) {
|
||||
public void renderToolTip(ItemStack stack, int x, int y) {
|
||||
List list;
|
||||
if (stack.getItem() instanceof ItemFluidPacket) {
|
||||
FluidStack fluid = ItemFluidPacket.getFluidStack(stack);
|
||||
|
||||
+251
-108
@@ -15,8 +15,6 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.implementations.tiles.IViewCellStorage;
|
||||
@@ -194,122 +192,267 @@ public class ContainerFluidMonitor extends FCContainerMonitor<IAEFluidStack> {
|
||||
this.dropItem(is);
|
||||
}
|
||||
|
||||
/**
|
||||
* Two operations, insert and extract.
|
||||
*
|
||||
* @param slotIndex The slot. If index == -1, the cursor held itemstack. Else, slotIndex indicates which slot was
|
||||
* shift clicked on.
|
||||
*/
|
||||
public void postChange(Iterable<IAEFluidStack> change, ItemStack fluidContainer, EntityPlayer player,
|
||||
int slotIndex) {
|
||||
int cursorItems;
|
||||
if (slotIndex == -1) {
|
||||
cursorItems = player.inventory.getItemStack().stackSize;
|
||||
} else {
|
||||
cursorItems = player.inventory.getStackInSlot(slotIndex).stackSize;
|
||||
}
|
||||
for (IAEFluidStack fluid : change) {
|
||||
IAEFluidStack nfluid = this.monitor.getStorageList().findPrecise(fluid);
|
||||
ItemStack out = fluidContainer.copy();
|
||||
out.stackSize = 1;
|
||||
// The primary output itemstack
|
||||
if (Util.FluidUtil.isEmpty(fluidContainer) && fluid != null) {
|
||||
// add fluid to tanks
|
||||
if (nfluid.getStackSize() <= 0) continue;
|
||||
final IAEFluidStack toExtract = nfluid.copy();
|
||||
MutablePair<Integer, ItemStack> fillStack = Util.FluidUtil.fillStack(out, toExtract.getFluidStack());
|
||||
if (fillStack.right == null || fillStack.left <= 0) continue;
|
||||
toExtract.setStackSize((long) fillStack.left * fluidContainer.stackSize);
|
||||
// The real result may don't match simulation result.
|
||||
if (fillStack.right.getItem() instanceof IFluidContainerItem) {
|
||||
IAEFluidStack real = this.host.getFluidInventory()
|
||||
.extractItems(toExtract, Actionable.MODULATE, this.getActionSource());
|
||||
if (real == null) continue;
|
||||
// Refill the container
|
||||
out = fluidContainer.copy();
|
||||
out.stackSize = 1;
|
||||
fillStack = Util.FluidUtil.fillStack(out, real.getFluidStack());
|
||||
fillStack.right.stackSize = (int) (real.getStackSize() / fillStack.left);
|
||||
out.stackSize = fillStack.right.stackSize;
|
||||
if ((int) (real.getStackSize() % fillStack.left) > 0) {
|
||||
this.dropItem(
|
||||
Util.FluidUtil.setFluidContainerAmount(
|
||||
fillStack.right,
|
||||
(int) (real.getStackSize() % fillStack.left)),
|
||||
1);
|
||||
out.stackSize++;
|
||||
}
|
||||
} else if (FluidContainerRegistry.isContainer(fillStack.right)) {
|
||||
IAEFluidStack real = this.host.getFluidInventory()
|
||||
.extractItems(toExtract, Actionable.MODULATE, this.getActionSource());
|
||||
if (real == null) continue;
|
||||
// Refill the container
|
||||
out = fluidContainer.copy();
|
||||
out.stackSize = 1;
|
||||
fillStack = Util.FluidUtil.fillStack(out, real.getFluidStack());
|
||||
fillStack.right.stackSize = (int) (real.getStackSize() / fillStack.left);
|
||||
out.stackSize = fillStack.right.stackSize;
|
||||
toExtract.setStackSize((long) fillStack.right.stackSize * fillStack.left);
|
||||
}
|
||||
this.dropItem(fillStack.right);
|
||||
// Situation 1.a: Empty fluid container, and nonnull slot
|
||||
extractFluid(fluid, fluidContainer, player, cursorItems);
|
||||
} else if (!Util.FluidUtil.isEmpty(fluidContainer)) {
|
||||
// add fluid to ae network
|
||||
AEFluidStack fluidStack = Util.getAEFluidFromItem(fluidContainer);
|
||||
final IAEFluidStack aeFluidStack = fluidStack.copy();
|
||||
// simulate result is incorrect. so I'm using other solution and ec2 both mod have same issues
|
||||
final IAEFluidStack notInserted = this.host.getFluidInventory()
|
||||
.injectItems(aeFluidStack, Actionable.MODULATE, this.getActionSource());
|
||||
MutablePair<Integer, ItemStack> drainStack = Util.FluidUtil
|
||||
.drainStack(out.copy(), aeFluidStack.getFluidStack());
|
||||
if (notInserted != null && notInserted.getStackSize() > 0) {
|
||||
if (fluidStack.getStackSize() == notInserted.getStackSize()) continue;
|
||||
aeFluidStack.decStackSize(notInserted.getStackSize());
|
||||
|
||||
if (drainStack.left > aeFluidStack.getStackSize()
|
||||
&& FluidContainerRegistry.isContainer(drainStack.right)) {
|
||||
aeFluidStack.setStackSize(drainStack.left - aeFluidStack.getStackSize());
|
||||
this.host.getFluidInventory()
|
||||
.extractItems(aeFluidStack, Actionable.MODULATE, this.getActionSource());
|
||||
continue;
|
||||
}
|
||||
|
||||
this.dropItem(drainStack.right, (int) (aeFluidStack.getStackSize() / drainStack.left)); // drop
|
||||
// empty
|
||||
// item
|
||||
out.stackSize = (int) (notInserted.getStackSize() / drainStack.left);
|
||||
if (drainStack.right.getItem() instanceof IFluidContainerItem) {
|
||||
if (notInserted.getStackSize() % drainStack.left > 0) {
|
||||
fluidStack.setStackSize((notInserted.getStackSize() % drainStack.left));
|
||||
((IFluidContainerItem) drainStack.right.getItem())
|
||||
.fill(drainStack.right, fluidStack.getFluidStack(), true);
|
||||
this.dropItem(drainStack.right, 1);
|
||||
}
|
||||
} else if (FluidContainerRegistry.isContainer(drainStack.right)) {
|
||||
if (notInserted.getStackSize() % drainStack.left > 0) {
|
||||
aeFluidStack.setStackSize(aeFluidStack.getStackSize() % drainStack.left);
|
||||
this.host.getFluidInventory()
|
||||
.extractItems(aeFluidStack, Actionable.MODULATE, this.getActionSource());
|
||||
out.stackSize++;
|
||||
}
|
||||
}
|
||||
if (slotIndex == -1) out.stackSize = fluidContainer.stackSize - out.stackSize;
|
||||
} else {
|
||||
if (slotIndex == -1) {
|
||||
out.stackSize = fluidContainer.stackSize;
|
||||
} else {
|
||||
out.stackSize = (int) (fluidContainer.stackSize
|
||||
- (aeFluidStack.getStackSize() / drainStack.left));
|
||||
}
|
||||
this.dropItem(drainStack.right, fluidContainer.stackSize); // drop empty item
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
if (slotIndex == -1) {
|
||||
player.inventory.getItemStack().stackSize = player.inventory.getItemStack().stackSize - out.stackSize;
|
||||
if (player.inventory.getItemStack().stackSize > 0) {
|
||||
FluidCraft.proxy.netHandler.sendTo(
|
||||
new SPacketFluidUpdate(new HashMap<>(), player.inventory.getItemStack()),
|
||||
(EntityPlayerMP) player);
|
||||
} else {
|
||||
player.inventory.setItemStack(null);
|
||||
FluidCraft.proxy.netHandler
|
||||
.sendTo(new SPacketFluidUpdate(new HashMap<>()), (EntityPlayerMP) player);
|
||||
}
|
||||
} else {
|
||||
player.inventory.setInventorySlotContents(slotIndex, out.stackSize > 0 ? out : null);
|
||||
// Situation 2.a: We are holding a non-empty container.
|
||||
insertFluid(fluidContainer, player, slotIndex, cursorItems);
|
||||
// End of situation 2.a
|
||||
}
|
||||
// No op (Any other situation)
|
||||
}
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* The insert operation. For input, we have an filled container stack. For outputs, we have the following: 1.
|
||||
* Leftover filled container stack - primary output. 2. Empty containers 3. Partially filled container x1 In order
|
||||
* above, the itemstack at `slotIndex` is transformed into the output.
|
||||
*/
|
||||
private void insertFluid(ItemStack fluidContainer, EntityPlayer player, int slotIndex, int heldContainers) {
|
||||
IAEFluidStack fluid;
|
||||
int fluidInTank;
|
||||
if (fluidContainer.getItem() instanceof IFluidContainerItem) {
|
||||
fluid = AEFluidStack.create(((IFluidContainerItem) fluidContainer.getItem()).getFluid(fluidContainer));
|
||||
fluidInTank = (int) fluid.getStackSize();
|
||||
} else if (FluidContainerRegistry.isContainer(fluidContainer)) {
|
||||
fluid = AEFluidStack.create(FluidContainerRegistry.getFluidForFilledItem(fluidContainer));
|
||||
fluidInTank = (int) fluid.getStackSize();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// Simulate to know how much will not be inserted
|
||||
IAEFluidStack canSend = fluid.copy();
|
||||
canSend.setStackSize((long) fluidInTank * fluidContainer.stackSize);
|
||||
final IAEFluidStack notInserted = this.host.getFluidInventory()
|
||||
.injectItems(canSend, Actionable.MODULATE, this.getActionSource());
|
||||
int emptyTanks = fluidContainer.stackSize;
|
||||
ItemStack partialStack = fluidContainer.copy();
|
||||
if (notInserted != null && notInserted.getStackSize() > 0) {
|
||||
// Here, we cannot insert everything into the system.
|
||||
if (canSend.getStackSize() == notInserted.getStackSize()) return; // System was full, no op
|
||||
// Now "refill" the buckets that couldn't enter the system
|
||||
int refilled = (int) (notInserted.getStackSize() / fluidInTank); // # of full tanks left
|
||||
emptyTanks -= refilled;
|
||||
final int remainder = (int) (notInserted.getStackSize() % fluidInTank); // partial tank
|
||||
// Now handle remaining if applicable
|
||||
if (remainder > 0) {
|
||||
notInserted.setStackSize(remainder);
|
||||
partialStack.stackSize = 1;
|
||||
if (partialStack.getItem() instanceof IFluidContainerItem) {
|
||||
((IFluidContainerItem) partialStack.getItem()).drain(partialStack, fluidInTank - remainder, true);
|
||||
} else if (FluidContainerRegistry.isContainer(fluidContainer)) {
|
||||
// For "whole containers" (need to round down, no remainders)
|
||||
ItemStack container = FluidContainerRegistry
|
||||
.fillFluidContainer(notInserted.getFluidStack(), fluidContainer);
|
||||
if (container == null) {
|
||||
// whatever, lets just not have the ME system get filled with any of its fluid
|
||||
emptyTanks++;
|
||||
notInserted.setStackSize(fluidInTank - remainder);
|
||||
this.host.getFluidInventory()
|
||||
.extractItems(notInserted, Actionable.MODULATE, this.getActionSource());
|
||||
partialStack.stackSize = 0;
|
||||
} else {
|
||||
partialStack = container;
|
||||
}
|
||||
}
|
||||
emptyTanks -= partialStack.stackSize;
|
||||
} else {
|
||||
partialStack.stackSize = 0;
|
||||
}
|
||||
} else {
|
||||
partialStack.stackSize = 0;
|
||||
}
|
||||
// Now that the 3 outputs are handled, we can now actually put the fluids in
|
||||
ItemStack emptyStack = fluidContainer.copy();
|
||||
emptyStack.stackSize = 1;
|
||||
if (emptyStack.getItem() instanceof IFluidContainerItem) {
|
||||
((IFluidContainerItem) emptyStack.getItem()).drain(emptyStack, fluidInTank, true);
|
||||
} else {
|
||||
emptyStack = FluidContainerRegistry.drainFluidContainer(emptyStack);
|
||||
}
|
||||
emptyStack.stackSize = emptyTanks;
|
||||
int extraTanks = heldContainers - emptyTanks - partialStack.stackSize;
|
||||
// Done. Put the output in the inventory or ground, and update stack size.
|
||||
boolean shouldSendStack = true;
|
||||
if (slotIndex == -1) {
|
||||
if (extraTanks > 0) {
|
||||
ItemStack stack = player.inventory.getItemStack();
|
||||
stack.stackSize = extraTanks;
|
||||
adjustStack(stack);
|
||||
dropItem(emptyStack);
|
||||
dropItem(partialStack);
|
||||
} else if (emptyTanks != 0) {
|
||||
adjustStack(emptyStack);
|
||||
player.inventory.setItemStack(emptyStack);
|
||||
dropItem(partialStack);
|
||||
} else if (partialStack.stackSize != 0) {
|
||||
player.inventory.setItemStack(partialStack);
|
||||
} else {
|
||||
player.inventory.setItemStack(null);
|
||||
shouldSendStack = false;
|
||||
}
|
||||
} else {
|
||||
ItemStack stack = player.inventory.getStackInSlot(slotIndex);
|
||||
if (extraTanks > 0) {
|
||||
stack.stackSize = extraTanks;
|
||||
adjustStack(stack);
|
||||
dropItem(emptyStack);
|
||||
dropItem(partialStack);
|
||||
} else if (emptyTanks != 0) {
|
||||
adjustStack(emptyStack);
|
||||
player.inventory.setInventorySlotContents(slotIndex, emptyStack);
|
||||
dropItem(partialStack);
|
||||
} else if (partialStack.stackSize != 0) {
|
||||
player.inventory.setInventorySlotContents(slotIndex, partialStack);
|
||||
} else {
|
||||
player.inventory.setItemStack(null);
|
||||
shouldSendStack = false;
|
||||
}
|
||||
}
|
||||
if (shouldSendStack) {
|
||||
FluidCraft.proxy.netHandler.sendTo(
|
||||
new SPacketFluidUpdate(new HashMap<>(), player.inventory.getItemStack()),
|
||||
(EntityPlayerMP) player);
|
||||
} else {
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(new HashMap<>()), (EntityPlayerMP) player);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The extract operation. For input, we have an empty container stack. For outputs, we have the following: 1.
|
||||
* Leftover empty container stack - primary output. 2. Filled containers (full) 3. Partially filled container x1 In
|
||||
* order above, the itemstack at `slotIndex` is transformed into the output.
|
||||
*/
|
||||
private void extractFluid(IAEFluidStack fluid, ItemStack fluidContainer, EntityPlayer player, int heldContainers) {
|
||||
IAEFluidStack storedFluid = this.monitor.getStorageList().findPrecise(fluid);
|
||||
if (storedFluid == null || storedFluid.getStackSize() <= 0) return;
|
||||
int capacity;
|
||||
if (fluidContainer.getItem() instanceof IFluidContainerItem) {
|
||||
capacity = ((IFluidContainerItem) fluidContainer.getItem()).getCapacity(fluidContainer);
|
||||
} else if (FluidContainerRegistry.isContainer(fluidContainer)) {
|
||||
// Fill with fluid container registry, or abort if it failed
|
||||
ItemStack dummy = FluidContainerRegistry.fillFluidContainer(storedFluid.getFluidStack(), fluidContainer);
|
||||
capacity = FluidContainerRegistry.getContainerCapacity(dummy);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (capacity == 0) return;
|
||||
// The fluidstack that we will try to extract from the system.
|
||||
final IAEFluidStack canExtract = storedFluid.copy();
|
||||
// Maximum amount of fluid we can extract with the given container(s). Guarantees that we won't
|
||||
// run into issues w/ remainder fluid later.
|
||||
canExtract.setStackSize((long) capacity * fluidContainer.stackSize);
|
||||
IAEFluidStack actualExtract = this.host.getFluidInventory()
|
||||
.extractItems(canExtract, Actionable.SIMULATE, this.getActionSource());
|
||||
if (actualExtract == null) return;
|
||||
// Calculate the number of full fluid containers we extracted
|
||||
long toExtract = actualExtract.getStackSize();
|
||||
int filledTanks = (int) (toExtract / capacity);
|
||||
int remainder = (int) (toExtract % capacity);
|
||||
int emptyTanks = heldContainers - filledTanks;
|
||||
// Fill the filled tanks
|
||||
ItemStack filledStack = fluidContainer.copy();
|
||||
filledStack.stackSize = 1;
|
||||
if (filledTanks > 0) {
|
||||
if (filledStack.getItem() instanceof IFluidContainerItem) {
|
||||
int amt = ((IFluidContainerItem) filledStack.getItem())
|
||||
.fill(filledStack, actualExtract.getFluidStack(), true);
|
||||
assert amt == capacity;
|
||||
} else {
|
||||
// Should not be NPE since we affirmed that we have enough capacity.
|
||||
filledStack = FluidContainerRegistry.fillFluidContainer(actualExtract.getFluidStack(), filledStack);
|
||||
assert capacity == FluidContainerRegistry.getContainerCapacity(filledStack);
|
||||
}
|
||||
filledStack.stackSize = filledTanks;
|
||||
} else {
|
||||
filledStack.stackSize = 0;
|
||||
}
|
||||
// Calculate the remaining fluid to extract, if any
|
||||
ItemStack partialStack = fluidContainer.copy();
|
||||
if (remainder > 0) {
|
||||
actualExtract.setStackSize(remainder);
|
||||
partialStack.stackSize = 1;
|
||||
if (partialStack.getItem() instanceof IFluidContainerItem) {
|
||||
int amt = ((IFluidContainerItem) partialStack.getItem())
|
||||
.fill(partialStack, actualExtract.getFluidStack(), true);
|
||||
assert amt == remainder;
|
||||
emptyTanks--;
|
||||
} else {
|
||||
ItemStack dummy = FluidContainerRegistry
|
||||
.fillFluidContainer(actualExtract.getFluidStack(), partialStack);
|
||||
if (dummy == null) {
|
||||
// Failed to fill partial...
|
||||
partialStack.stackSize = 0;
|
||||
toExtract -= remainder;
|
||||
} else {
|
||||
partialStack = dummy;
|
||||
toExtract -= FluidContainerRegistry.getContainerCapacity(partialStack);
|
||||
emptyTanks--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
partialStack.stackSize = 0;
|
||||
}
|
||||
// Now perform the real extraction.
|
||||
actualExtract.setStackSize(toExtract);
|
||||
this.host.getFluidInventory().extractItems(canExtract, Actionable.MODULATE, this.getActionSource());
|
||||
|
||||
// Done. Put the output in the inventory or ground, and update stack size.
|
||||
// We can assume slotIndex == -1, since we don't actually allow extraction via shift click.
|
||||
boolean shouldSendStack = true;
|
||||
if (emptyTanks > 0) {
|
||||
ItemStack emptyStack = player.inventory.getItemStack();
|
||||
emptyStack.stackSize = emptyTanks;
|
||||
adjustStack(emptyStack);
|
||||
dropItem(filledStack);
|
||||
dropItem(partialStack);
|
||||
} else if (filledStack.stackSize != 0) {
|
||||
adjustStack(filledStack);
|
||||
player.inventory.setItemStack(filledStack);
|
||||
dropItem(partialStack);
|
||||
} else if (partialStack.stackSize != 0) {
|
||||
player.inventory.setItemStack(partialStack);
|
||||
} else {
|
||||
player.inventory.setItemStack(null);
|
||||
shouldSendStack = false;
|
||||
}
|
||||
if (shouldSendStack) {
|
||||
FluidCraft.proxy.netHandler.sendTo(
|
||||
new SPacketFluidUpdate(new HashMap<>(), player.inventory.getItemStack()),
|
||||
(EntityPlayerMP) player);
|
||||
} else {
|
||||
FluidCraft.proxy.netHandler.sendTo(new SPacketFluidUpdate(new HashMap<>()), (EntityPlayerMP) player);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void adjustStack(ItemStack stack) {
|
||||
if (stack.stackSize > stack.getMaxStackSize()) {
|
||||
dropItem(stack, stack.stackSize - stack.getMaxStackSize());
|
||||
stack.stackSize = stack.getMaxStackSize();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isEssentiaMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ public class Config {
|
||||
public static boolean removeRecipe;
|
||||
public static boolean blacklistEssentiaGas;
|
||||
public static double portableCellBattery;
|
||||
public static int packetSize;
|
||||
public static int packetRate;
|
||||
public static boolean replaceEC2;
|
||||
|
||||
public static void run() {
|
||||
loadCategory();
|
||||
@@ -51,7 +54,18 @@ public class Config {
|
||||
"Blacklist Essentia Gas from Thaumic Energistics, so they won't be stored in Fluid Storage Cells.");
|
||||
portableCellBattery = Config.get("Fluid Craft for AE2", "Portable Fluid Cell Battery Capacity", 20000D)
|
||||
.getDouble();
|
||||
|
||||
packetSize = Config.get("Fluid Craft for AE2", "packetSize", 256, "Number of items to be sent per packet")
|
||||
.getInt();
|
||||
if (packetSize <= 0) packetSize = 256;
|
||||
packetRate = Config
|
||||
.get("Fluid Craft for AE2", "packetRate", 50, "Period at which packets are dispatched, in ms.")
|
||||
.getInt();
|
||||
if (packetRate <= 0) packetRate = 50;
|
||||
replaceEC2 = Config.getBoolean(
|
||||
"Fluid Craft for AE2",
|
||||
"replaceEC2",
|
||||
true,
|
||||
"Set true to handle missing item mappings from EC2. Note to work properly, you must have all relevant parts.");
|
||||
if (Config.hasChanged()) Config.save();
|
||||
}
|
||||
|
||||
|
||||
@@ -131,12 +131,19 @@ public class BlockCertusQuartzTank extends BaseBlockContainer implements IRegist
|
||||
if (liquid != null) {
|
||||
int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
|
||||
if (amountFilled != 0 && !entityplayer.capabilities.isCreativeMode && current.getItem() != null) {
|
||||
ItemStack empty;
|
||||
if (FluidContainerRegistry.isContainer(current)) {
|
||||
empty = FluidContainerRegistry.drainFluidContainer(current);
|
||||
} else {
|
||||
// Try this as a fallback.
|
||||
entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItem(current));
|
||||
empty = current.getItem().getContainerItem(current);
|
||||
}
|
||||
if (current.stackSize > 1) {
|
||||
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
|
||||
entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItem(current));
|
||||
entityplayer.inventory.addItemStackToInventory(empty);
|
||||
} else {
|
||||
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = current.getItem()
|
||||
.getContainerItem(current);
|
||||
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = empty;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluid
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
public double getIdleDrain(ItemStack is) {
|
||||
return this.idleDrain;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ItemCreativeFluidStorageCell extends AEBaseItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
public double getIdleDrain(ItemStack is) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ public class ItemPortableFluidCell extends AEBasePoweredItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
public double getIdleDrain(ItemStack is) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,40 +119,41 @@ public class PartFluidExportBus extends FCSharedFluidBus implements ICraftingReq
|
||||
IAEFluidStack fluid = AEFluidStack
|
||||
.create(ItemFluidPacket.getFluidStack(getInv().getStackInSlot(slotToExport)));
|
||||
if (fluid != null) {
|
||||
boolean isAllowed = true;
|
||||
|
||||
final IAEFluidStack toExtract = fluid.copy();
|
||||
|
||||
toExtract.setStackSize(this.calculateAmountToSend());
|
||||
|
||||
fluid.setStackSize(this.calculateAmountToSend());
|
||||
if (this.craftOnly()) {
|
||||
isAllowed = this.craftingTracker.handleCrafting(
|
||||
this.didSomething = this.craftingTracker.handleCrafting(
|
||||
i,
|
||||
toExtract.getStackSize(),
|
||||
ItemFluidDrop.newAeStack(toExtract),
|
||||
fluid.getStackSize(),
|
||||
ItemFluidDrop.newAeStack(fluid),
|
||||
destination,
|
||||
this.getTile().getWorldObj(),
|
||||
this.getProxy().getGrid(),
|
||||
cg,
|
||||
this.source);
|
||||
continue;
|
||||
}
|
||||
|
||||
int space = fh.fill(this.getSide().getOpposite(), toExtract.getFluidStack(), false);
|
||||
toExtract.setStackSize(space);
|
||||
final IAEFluidStack real = inv.extractItems(toExtract, Actionable.MODULATE, this.source);
|
||||
if (real != null && isAllowed) {
|
||||
// Find out how much to push
|
||||
final IAEFluidStack toPush = fluid.copy();
|
||||
final int amtToInsert = fh.fill(this.getSide().getOpposite(), toPush.getFluidStack(), false);
|
||||
toPush.setStackSize(amtToInsert);
|
||||
// Extract from the ME system. This might not be the same amount we actually send...
|
||||
final IAEFluidStack real = inv.extractItems(toPush, Actionable.MODULATE, this.source);
|
||||
if (real != null) {
|
||||
int realInserted = fh.fill(this.getSide().getOpposite(), real.getFluidStack(), true);
|
||||
if (realInserted < real.getStackSize()) {
|
||||
toExtract.setStackSize(real.getStackSize() - realInserted);
|
||||
inv.injectItems(toExtract, Actionable.MODULATE, this.source);
|
||||
// Could not use the entirety of the amount we extracted, so put it back.
|
||||
// This can result in voiding fluids if there's nowhere for the fluids to go.
|
||||
fluid.setStackSize(real.getStackSize() - realInserted);
|
||||
inv.injectItems(fluid, Actionable.MODULATE, this.source);
|
||||
}
|
||||
this.fluidToSend -= realInserted;
|
||||
didSomething = true;
|
||||
} else if (this.isCraftingEnabled()) {
|
||||
this.craftingTracker.handleCrafting(
|
||||
// If we didn't send anything, try crafting it if we can.
|
||||
this.didSomething = this.craftingTracker.handleCrafting(
|
||||
i,
|
||||
toExtract.getStackSize(),
|
||||
ItemFluidDrop.newAeStack(toExtract),
|
||||
fluid.getStackSize(),
|
||||
ItemFluidDrop.newAeStack(fluid),
|
||||
destination,
|
||||
this.getTile().getWorldObj(),
|
||||
this.getProxy().getGrid(),
|
||||
|
||||
@@ -68,11 +68,15 @@ public class PartFluidImportBus extends FCSharedFluidBus {
|
||||
if (te instanceof IFluidHandler) {
|
||||
try {
|
||||
final IFluidHandler fh = (IFluidHandler) te;
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getFluidInventory();
|
||||
FluidTankInfo[] tanksInfo = fh.getTankInfo(this.getSide().getOpposite());
|
||||
if (tanksInfo == null) {
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getFluidInventory();
|
||||
int maxDrain = this.calculateAmountToSend();
|
||||
boolean drained = false;
|
||||
FluidTankInfo[] tanksInfo = fh.getTankInfo(this.getSide().getOpposite());
|
||||
|
||||
for (FluidTankInfo tankInfo : tanksInfo) {
|
||||
if (tankInfo.fluid == null) {
|
||||
continue;
|
||||
|
||||
@@ -69,6 +69,6 @@ public class FluidCellHandler implements ICellHandler {
|
||||
@Override
|
||||
public double cellIdleDrain(final ItemStack is, final IMEInventory handler) {
|
||||
final IFluidCellInventory inv = ((IFluidCellInventoryHandler) handler).getCellInv();
|
||||
return inv.getIdleDrain();
|
||||
return inv.getIdleDrain(is);
|
||||
}
|
||||
}
|
||||
@@ -23,23 +23,25 @@ import appeng.util.Platform;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
|
||||
import com.glodblock.github.common.item.ItemCreativeFluidStorageCell;
|
||||
import com.glodblock.github.crossmod.extracells.storage.ProxyFluidCellInventory;
|
||||
import com.glodblock.github.crossmod.extracells.storage.ProxyFluidStorageCell;
|
||||
|
||||
public class FluidCellInventory implements IFluidCellInventory {
|
||||
|
||||
private static final String FLUID_TYPE_TAG = "ft";
|
||||
private static final String FLUID_COUNT_TAG = "fc";
|
||||
private static final String FLUID_SLOT = "#";
|
||||
private static final String FLUID_SLOT_COUNT = "@";
|
||||
protected static final String FLUID_TYPE_TAG = "ft";
|
||||
protected static final String FLUID_COUNT_TAG = "fc";
|
||||
protected static final String FLUID_SLOT = "#";
|
||||
protected static final String FLUID_SLOT_COUNT = "@";
|
||||
protected IStorageFluidCell cellType;
|
||||
private static String[] fluidSlots;
|
||||
private static String[] fluidSlotCount;
|
||||
protected static String[] fluidSlots;
|
||||
protected static String[] fluidSlotCount;
|
||||
protected final ItemStack cellItem;
|
||||
private final ISaveProvider container;
|
||||
private final int MAX_TYPE = 63;
|
||||
private long storedFluidCount;
|
||||
private short storedFluids;
|
||||
protected long storedFluidCount;
|
||||
protected short storedFluids;
|
||||
protected IItemList<IAEFluidStack> cellFluids;
|
||||
private final NBTTagCompound tagCompound;
|
||||
protected final NBTTagCompound tagCompound;
|
||||
public static final int singleByteAmount = 256 * 8;
|
||||
|
||||
public FluidCellInventory(final ItemStack o, final ISaveProvider container) throws AppEngException {
|
||||
@@ -80,6 +82,8 @@ public class FluidCellInventory implements IFluidCellInventory {
|
||||
try {
|
||||
if (o.getItem() instanceof ItemCreativeFluidStorageCell) {
|
||||
return new FluidCellInventoryHandler(new CreativeFluidCellInventory(o, container2));
|
||||
} else if (o.getItem() instanceof ProxyFluidStorageCell) {
|
||||
return new FluidCellInventoryHandler(new ProxyFluidCellInventory(o, container2));
|
||||
} else {
|
||||
return new FluidCellInventoryHandler(new FluidCellInventory(o, container2));
|
||||
}
|
||||
@@ -105,8 +109,8 @@ public class FluidCellInventory implements IFluidCellInventory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
return this.cellType.getIdleDrain();
|
||||
public double getIdleDrain(ItemStack is) {
|
||||
return this.cellType.getIdleDrain(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,7 @@ import com.glodblock.github.util.Util;
|
||||
|
||||
public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack> implements IFluidCellInventoryHandler {
|
||||
|
||||
FluidCellInventoryHandler(final IMEInventory<IAEFluidStack> c) {
|
||||
protected FluidCellInventoryHandler(final IMEInventory<IAEFluidStack> c) {
|
||||
super(c, StorageChannel.FLUIDS);
|
||||
|
||||
final IFluidCellInventory ci = this.getCellInv();
|
||||
@@ -32,7 +32,6 @@ public class FluidCellInventoryHandler extends MEInventoryHandler<IAEFluidStack>
|
||||
final ItemStack is = config.getStackInSlot(x);
|
||||
if (Util.getFluidFromItem(is) != null) {
|
||||
priorityList.add(AEFluidStack.create(Util.getFluidFromItem(is)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!priorityList.isEmpty()) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface IFluidCellInventory extends IMEInventory<IAEFluidStack> {
|
||||
/**
|
||||
* @return idle cost for this Storage Cell
|
||||
*/
|
||||
double getIdleDrain();
|
||||
double getIdleDrain(ItemStack is);
|
||||
|
||||
/**
|
||||
* @return access configured list
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface IStorageFluidCell extends ICellWorkbenchItem {
|
||||
|
||||
boolean isStorageCell(ItemStack i);
|
||||
|
||||
double getIdleDrain();
|
||||
double getIdleDrain(ItemStack is);
|
||||
|
||||
int getTotalTypes(ItemStack cellItem);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.glodblock.github.crossmod.extracells;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class EC2Replacer {
|
||||
|
||||
/**
|
||||
* Should be called if and only if replaceEC2 config is true and EC2 not present. Registers proxy items for the
|
||||
* entire EC2 mod. After running this once, you should set replaceEC2 back to false.
|
||||
*/
|
||||
public static void initReplacer() {
|
||||
ItemReplacements.init();
|
||||
}
|
||||
|
||||
public static void replaceExtraCells(FMLMissingMappingsEvent event) {
|
||||
List<FMLMissingMappingsEvent.MissingMapping> mappings = event.getAll();
|
||||
for (FMLMissingMappingsEvent.MissingMapping m : mappings) {
|
||||
if (m.type == GameRegistry.Type.ITEM && ItemReplacements.registry.containsKey(m.name)) {
|
||||
Item toRemap = ItemReplacements.registry.get(m.name);
|
||||
m.remap(toRemap);
|
||||
} else {
|
||||
m.warn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
package com.glodblock.github.crossmod.extracells;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
|
||||
import com.glodblock.github.common.item.ItemMultiFluidStorageCell;
|
||||
import com.glodblock.github.crossmod.extracells.parts.*;
|
||||
import com.glodblock.github.crossmod.extracells.storage.*;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/**
|
||||
* Shell class to organize proxy replacements and hide the ugliness
|
||||
*/
|
||||
public class ItemReplacements {
|
||||
|
||||
protected static Map<String, Item> registry;
|
||||
|
||||
static void init() {
|
||||
registry = new HashMap<>(23);
|
||||
ProxyFluidBusIO.init();
|
||||
ItemReplacements.proxyItems();
|
||||
ItemReplacements.proxyPartItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register proxy items (non-parts)
|
||||
*/
|
||||
static void proxyItems() {
|
||||
deprecateFluidStorage("storage.fluid", 0, ItemAndBlockHolder.CELL1KM, 1, 8, 0.5);
|
||||
deprecateFluidStorage("storage.fluid", 1, ItemAndBlockHolder.CELL4KM, 4, 32, 1.0);
|
||||
deprecateFluidStorage("storage.fluid", 2, ItemAndBlockHolder.CELL16KM, 16, 128, 1.5);
|
||||
deprecateFluidStorage("storage.fluid", 3, ItemAndBlockHolder.CELL64KM, 64, 512, 2.0);
|
||||
deprecateFluidStorage("storage.fluid", 4, ItemAndBlockHolder.CELL256KM, 256, 2048, 2.5);
|
||||
deprecateFluidStorage("storage.fluid", 5, ItemAndBlockHolder.CELL1024KM, 1024, 8192, 3.0);
|
||||
deprecateFluidStorage("storage.fluid", 6, ItemAndBlockHolder.CELL4096KM, 4096, 32768, 3.5);
|
||||
deprecateFluidStorage("storage.fluid", 7, ItemAndBlockHolder.CELL16384KM, 16384, 131072, 4.0);
|
||||
// Thanks, AEApi.
|
||||
AEApi.instance().registries().cell().addCellHandler(new ProxyItemCellHandler());
|
||||
AEApi.instance().registries().cell().addCellHandler(new ProxyVoidCellHandler());
|
||||
deprecateItemStorage(0, AEApi.instance().definitions().items().cell256k(), 256, 2048, 2.5);
|
||||
deprecateItemStorage(1, AEApi.instance().definitions().items().cell1024k(), 1024, 8192, 3.0);
|
||||
deprecateItemStorage(2, AEApi.instance().definitions().items().cell4096k(), 4096, 32768, 3.5);
|
||||
deprecateItemStorage(3, AEApi.instance().definitions().items().cell16384k(), 16384, 131072, 4.0);
|
||||
deprecateItemStorage(4, AEApi.instance().definitions().items().cellContainer(), 65536, 8, 2.0, 1);
|
||||
deprecateExtremeStorage(
|
||||
"storage.physical.advanced.quantum",
|
||||
0,
|
||||
AEApi.instance().definitions().items().cellQuantum(),
|
||||
Integer.MAX_VALUE / 16,
|
||||
4096,
|
||||
1000.0);
|
||||
deprecateExtremeStorage(
|
||||
"storage.physical.advanced.singularity",
|
||||
0,
|
||||
AEApi.instance().definitions().items().cellSingularity(),
|
||||
Long.MAX_VALUE / 16,
|
||||
4096,
|
||||
15000.0);
|
||||
// Deprecate void cell manually
|
||||
ProxyVoidStorageCell voidCell = new ProxyVoidStorageCell();
|
||||
GameRegistry.registerItem(voidCell, "ec2placeholder.storage.physical.void");
|
||||
registry.put("extracells:storage.physical.void", voidCell);
|
||||
deprecateItem("pattern.fluid", ItemAndBlockHolder.PATTERN);
|
||||
deprecateItem("terminal.fluid.wireless", ItemAndBlockHolder.WIRELESS_FLUID_TERM);
|
||||
/* Storage casings */
|
||||
deprecateItem("storage.casing", 0, AEApi.instance().definitions().materials().emptyAdvancedStorageCell());
|
||||
deprecateItem("storage.casing", 1, ItemAndBlockHolder.CELL_HOUSING, 2);
|
||||
/* Storage components (1k component, etc.) */
|
||||
deprecateItem("storage.component", 0, AEApi.instance().definitions().materials().cell256kPart());
|
||||
deprecateItem("storage.component", 1, AEApi.instance().definitions().materials().cell1024kPart());
|
||||
deprecateItem("storage.component", 2, AEApi.instance().definitions().materials().cell4096kPart());
|
||||
deprecateItem("storage.component", 3, AEApi.instance().definitions().materials().cell16384kPart());
|
||||
deprecateItem("storage.component", 4, ItemAndBlockHolder.CELL_PART, 0);
|
||||
deprecateItem("storage.component", 5, ItemAndBlockHolder.CELL_PART, 1);
|
||||
deprecateItem("storage.component", 6, ItemAndBlockHolder.CELL_PART, 2);
|
||||
deprecateItem("storage.component", 7, ItemAndBlockHolder.CELL_PART, 3);
|
||||
deprecateItem("storage.component", 8, ItemAndBlockHolder.CELL_PART, 4);
|
||||
deprecateItem("storage.component", 9, ItemAndBlockHolder.CELL_PART, 5);
|
||||
deprecateItem("storage.component", 10, ItemAndBlockHolder.CELL_PART, 6);
|
||||
deprecateItem("terminal.universal.wireless", ItemAndBlockHolder.WIRELESS_ULTRA_TERM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register proxy part items.
|
||||
*/
|
||||
static void proxyPartItems() {
|
||||
deprecateItemPart(0, ItemAndBlockHolder.FLUID_EXPORT_BUS, ProxyFluidBusIO::new);
|
||||
deprecateItemPart(1, ItemAndBlockHolder.FLUID_IMPORT_BUS, ProxyFluidBusIO::new);
|
||||
deprecateItemPart(2, ItemAndBlockHolder.FLUID_STORAGE_BUS, ProxyFluidStorage::new);
|
||||
deprecateItemPart(3, ItemAndBlockHolder.FLUID_TERM, ProxyPart::new);
|
||||
deprecateItemPart(4, ItemAndBlockHolder.FLUID_LEVEL_EMITTER, ProxyLevelEmitter::new);
|
||||
deprecateItemPart(9, ItemAndBlockHolder.FLUID_INTERFACE, ProxyFluidInterface::new);
|
||||
deprecateItemPart(10, ItemAndBlockHolder.FLUID_STORAGE_MONITOR, ProxyStorageMonitor::new);
|
||||
deprecateItemPart(11, ItemAndBlockHolder.FLUID_CONVERSION_MONITOR, ProxyStorageMonitor::new);
|
||||
}
|
||||
|
||||
private static ProxyItem getOrBuildItem(String srcName) {
|
||||
final String fullName = "extracells:" + srcName;
|
||||
ProxyItem proxy = (ProxyItem) registry.get(fullName);
|
||||
if (proxy == null) {
|
||||
proxy = new ProxyItem(srcName);
|
||||
registry.put(fullName, proxy);
|
||||
proxy.register();
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
private static ProxyFluidStorageCell getOrBuildFluidStorage(String srcName) {
|
||||
final String fullName = "extracells:" + srcName;
|
||||
ProxyFluidStorageCell proxy = (ProxyFluidStorageCell) registry.get(fullName);
|
||||
if (proxy == null) {
|
||||
proxy = new ProxyFluidStorageCell(srcName);
|
||||
registry.put(fullName, proxy);
|
||||
proxy.register();
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
private static ProxyItemStorageCell getOrBuildItemStorage() {
|
||||
final String fullName = "extracells:storage.physical";
|
||||
ProxyItemStorageCell proxy = (ProxyItemStorageCell) registry.get(fullName);
|
||||
if (proxy == null) {
|
||||
proxy = new ProxyItemStorageCell("storage.physical");
|
||||
registry.put(fullName, proxy);
|
||||
proxy.register();
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
private static ProxyExtremeStorageCell getOrBuildItemStorage(String srcName) {
|
||||
final String fullName = "extracells:" + srcName;
|
||||
ProxyExtremeStorageCell proxy = (ProxyExtremeStorageCell) registry.get(fullName);
|
||||
if (proxy == null) {
|
||||
proxy = new ProxyExtremeStorageCell(srcName);
|
||||
registry.put(fullName, proxy);
|
||||
proxy.register();
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecate a simple item.
|
||||
*
|
||||
* @param srcName name of the to-be-replaced item without the mod id prefix
|
||||
* @param srcMeta meta of the to-be-replaced item
|
||||
* @param replacement item that will replace src
|
||||
* @param targetMeta meta of the item that will replace src
|
||||
*/
|
||||
private static void deprecateItem(String srcName, int srcMeta, Item replacement, int targetMeta) {
|
||||
getOrBuildItem(srcName).addMetaReplacement(srcMeta, replacement, targetMeta);
|
||||
}
|
||||
|
||||
static void deprecateItemBlock(String srcName, int srcMeta, Item replacement, int targetMeta) {
|
||||
getOrBuildItem("itemBlock." + srcName).addMetaReplacement(srcMeta, replacement, targetMeta);
|
||||
}
|
||||
|
||||
private static void deprecateItem(String srcName, Item replacement) {
|
||||
deprecateItem(srcName, 0, replacement, 0);
|
||||
}
|
||||
|
||||
private static void deprecateItem(String srcName, int srcMeta, IItemDefinition replacement) {
|
||||
if (replacement.isEnabled()) {
|
||||
deprecateItem(
|
||||
srcName,
|
||||
srcMeta,
|
||||
replacement.maybeItem().get(),
|
||||
replacement.maybeStack(1).get().getItemDamage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void deprecateItemPart(int srcMeta, Item replacement,
|
||||
Function<ProxyPartItem, ProxyPart> partBuilder) {
|
||||
final String fullName = "extracells:part.base";
|
||||
ProxyPartItem proxyItem = (ProxyPartItem) registry.get(fullName);
|
||||
if (proxyItem == null) {
|
||||
proxyItem = new ProxyPartItem("part.base");
|
||||
registry.put(fullName, proxyItem);
|
||||
proxyItem.register();
|
||||
}
|
||||
proxyItem.addItemPart(srcMeta, replacement, partBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecate a fluid storage item. Note that we can't access the properties directly, so we need to do this
|
||||
*/
|
||||
private static void deprecateFluidStorage(String srcName, int srcMeta, ItemMultiFluidStorageCell replacement,
|
||||
long kilobytes, int bytesPerType, double idleDrain) {
|
||||
ProxyFluidStorageCell proxyItem = getOrBuildFluidStorage(srcName);
|
||||
ProxyItem.ProxyStorageEntry entry = new ProxyItem.ProxyStorageEntry(
|
||||
replacement,
|
||||
kilobytes,
|
||||
bytesPerType,
|
||||
idleDrain);
|
||||
proxyItem.addMetaReplacement(srcMeta, entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecate a storage item. This goes through AEAPI, as AE2FC doesn't have any item cells. If the item is disabled
|
||||
* in AEAPI, the replacement will not be registered!
|
||||
*/
|
||||
private static void deprecateItemStorage(int srcMeta, IItemDefinition replacement, long kilobytes, int bytesPerType,
|
||||
double idleDrain) {
|
||||
if (replacement.isEnabled()) {
|
||||
ProxyItemStorageCell item = getOrBuildItemStorage();
|
||||
int meta = replacement.maybeStack(1).get().getItemDamage();
|
||||
ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry(
|
||||
replacement.maybeItem().get(),
|
||||
kilobytes,
|
||||
bytesPerType,
|
||||
idleDrain);
|
||||
item.addMetaReplacement(srcMeta, storage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecate a storage item. This goes through AEAPI, as AE2FC doesn't have any item cells. If the item is disabled
|
||||
* in AEAPI, the replacement will not be registered!
|
||||
*/
|
||||
private static void deprecateItemStorage(int srcMeta, IItemDefinition replacement, long kilobytes, int bytesPerType,
|
||||
double idleDrain, int types) {
|
||||
if (replacement.isEnabled()) {
|
||||
ProxyItemStorageCell item = getOrBuildItemStorage();
|
||||
int meta = replacement.maybeStack(1).get().getItemDamage();
|
||||
ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry(
|
||||
replacement.maybeItem().get(),
|
||||
kilobytes,
|
||||
bytesPerType,
|
||||
idleDrain,
|
||||
types);
|
||||
item.addMetaReplacement(srcMeta, storage);
|
||||
}
|
||||
}
|
||||
|
||||
private static void deprecateExtremeStorage(String srcName, int srcMeta, IItemDefinition replacement, long bytes,
|
||||
int bytesPerType, double idleDrain) {
|
||||
if (replacement.isEnabled()) {
|
||||
ProxyExtremeStorageCell item = getOrBuildItemStorage(srcName);
|
||||
int meta = replacement.maybeStack(1).get().getItemDamage();
|
||||
ProxyItem.ProxyItemEntry storage = new ProxyItem.ProxyStorageEntry(
|
||||
replacement.maybeItem().get(),
|
||||
bytes / 1024,
|
||||
bytesPerType,
|
||||
idleDrain);
|
||||
item.addMetaReplacement(srcMeta, storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.glodblock.github.crossmod.extracells;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.item.FCBaseItem;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/**
|
||||
* EC2ProxyItem - Item that "holds" the data of a missing item.
|
||||
*/
|
||||
public class ProxyItem extends FCBaseItem {
|
||||
|
||||
protected final String name;
|
||||
|
||||
/**
|
||||
* Maps a metadata value to a replacement.
|
||||
*/
|
||||
protected final Map<Integer, ProxyItemEntry> replacements;
|
||||
|
||||
public ProxyItem(String ec2itemName) {
|
||||
this.name = ec2itemName;
|
||||
this.replacements = new HashMap<>();
|
||||
setUnlocalizedName("ec2placeholder." + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FCBaseItem register() {
|
||||
GameRegistry.registerItem(this, "ec2placeholder." + name, FluidCraft.MODID);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void addMetaReplacement(int srcMeta, Item replacement, int targetMeta) {
|
||||
this.replacements.put(srcMeta, new ProxyItemEntry(replacement, targetMeta));
|
||||
}
|
||||
|
||||
protected void addMetaReplacement(int srcMeta, ProxyItemEntry replacement) {
|
||||
this.replacements.put(srcMeta, replacement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasSubtypes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean p_77624_4_) {
|
||||
int meta = stack.getItemDamage();
|
||||
ProxyItemEntry itemRepl = replacements.get(meta);
|
||||
if (itemRepl != null) {
|
||||
info.add(EnumChatFormatting.RED + "Extra Cells Placeholder for:");
|
||||
info.add(EnumChatFormatting.AQUA + itemRepl.replacement.getUnlocalizedName());
|
||||
info.add(EnumChatFormatting.GOLD + "Put in your inventory to get a replacement.");
|
||||
info.add(EnumChatFormatting.GOLD + "It will disappear if no replacement was found.");
|
||||
info.add(EnumChatFormatting.RED + "Report missing conversions on the Github.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int p_77663_4_, boolean p_77663_5_) {
|
||||
if (!worldIn.isRemote && entityIn instanceof EntityPlayer) {
|
||||
EntityPlayer player = (EntityPlayer) entityIn;
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); ++i) {
|
||||
ItemStack s = player.inventory.getStackInSlot(i);
|
||||
if (s == stack) {
|
||||
int meta = stack.getItemDamage();
|
||||
ProxyItemEntry r = replacements.get(meta);
|
||||
if (r == null) {
|
||||
player.inventory.setInventorySlotContents(i, null);
|
||||
} else {
|
||||
ItemStack replaceStack = new ItemStack(r.replacement, stack.stackSize, r.replacementMeta);
|
||||
if (stack.hasTagCompound()) {
|
||||
replaceStack.setTagCompound(r.replaceNBT(stack.getTagCompound()));
|
||||
}
|
||||
player.inventory.setInventorySlotContents(i, replaceStack);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class for a mapping from source (Item, meta) -> replacement (Item, meta). Optionally, override the
|
||||
* {@link ProxyItemEntry#replaceNBT(NBTTagCompound)} method for custom NBT migration.
|
||||
*/
|
||||
protected static class ProxyItemEntry {
|
||||
|
||||
protected final Item replacement;
|
||||
protected final int replacementMeta;
|
||||
|
||||
/**
|
||||
* Creates a Proxy Replacement.
|
||||
*
|
||||
* @param replacement Item that will replace the other.
|
||||
* @param replacementMeta Metadata/damage value of the replacement
|
||||
*/
|
||||
protected ProxyItemEntry(Item replacement, int replacementMeta) {
|
||||
this.replacement = replacement;
|
||||
this.replacementMeta = replacementMeta;
|
||||
}
|
||||
|
||||
NBTTagCompound replaceNBT(NBTTagCompound compound) {
|
||||
System.out.println(compound);
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class ProxyStorageEntry extends ProxyItemEntry {
|
||||
|
||||
public final long maxBytes;
|
||||
public final int bytesPerType;
|
||||
public final double idleDrain;
|
||||
public final int types;
|
||||
|
||||
protected ProxyStorageEntry(Item replacement, long kilobytes, int bytesPerType, double idleDrain) {
|
||||
super(replacement, 0);
|
||||
this.maxBytes = kilobytes * 1024;
|
||||
this.bytesPerType = bytesPerType;
|
||||
this.idleDrain = idleDrain;
|
||||
this.types = 63;
|
||||
}
|
||||
|
||||
protected ProxyStorageEntry(Item replacement, long kilobytes, int bytesPerType, double idleDrain, int types) {
|
||||
super(replacement, 0);
|
||||
this.maxBytes = kilobytes * 1024;
|
||||
this.bytesPerType = bytesPerType;
|
||||
this.idleDrain = idleDrain;
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
@Override
|
||||
NBTTagCompound replaceNBT(NBTTagCompound compound) {
|
||||
if (compound != null && compound.hasKey("ecc")) {
|
||||
compound.removeTag("ecc");
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package com.glodblock.github.crossmod.extracells;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.parts.*;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* ProxyPart is expected to be immediately replaced with the replacement part on load.
|
||||
*/
|
||||
public class ProxyPart implements IPart, IPartDeprecated {
|
||||
|
||||
/**
|
||||
* Prevent memory leaks by having one of the instances be a weak ref.
|
||||
*/
|
||||
private final WeakReference<ProxyPartItem> item;
|
||||
|
||||
/**
|
||||
* Name for debug
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
public ProxyPart(ProxyPartItem item) {
|
||||
this.item = new WeakReference<>(item);
|
||||
this.name = item.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(PartItemStack type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer) {}
|
||||
|
||||
@Override
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer) {}
|
||||
|
||||
@Override
|
||||
public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer) {}
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingTexture() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDynamicRender() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {}
|
||||
|
||||
@Override
|
||||
public int getLightLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLadder(EntityLivingBase entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged() {}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) {}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getGridNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(Entity entity) {}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld() {}
|
||||
|
||||
@Override
|
||||
public void addToWorld() {}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile) {}
|
||||
|
||||
@Override
|
||||
public boolean onActivate(EntityPlayer player, Vec3 pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShiftActivate(EntityPlayer player, Vec3 pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched) {}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random r) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side) {}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOn(BusSupport what) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper boxes) {}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound transformPart(NBTTagCompound def) {
|
||||
int meta = def.getShort("Damage");
|
||||
if (item.get() == null) {
|
||||
throw new NullPointerException("Umm, this wasn't supposed to happen. The ref item " + name + " was GC'd.");
|
||||
}
|
||||
ProxyItem.ProxyItemEntry r = item.get().replacements.get(meta);
|
||||
def.setInteger("id", Item.getIdFromItem(r.replacement));
|
||||
def.setShort("Damage", (short) r.replacementMeta);
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound transformNBT(NBTTagCompound extra) {
|
||||
return extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new fluid display NBT tag from the fluid name
|
||||
*/
|
||||
public static NBTTagCompound createFluidDisplayTag(String fluidName) {
|
||||
NBTTagCompound fluidDisplay = new NBTTagCompound();
|
||||
Fluid fluid = FluidRegistry.getFluid(fluidName);
|
||||
if (fluid != null) {
|
||||
ItemStack fluidPacket = new ItemStack(GameRegistry.findItem("ae2fc", "fluid_packet"), 1, 0);
|
||||
NBTTagCompound fluidPacketTag = new NBTTagCompound();
|
||||
// FluidStack
|
||||
FluidStack fluidStack = new FluidStack(fluid, 1000);
|
||||
NBTTagCompound fluidStackNbt = new NBTTagCompound();
|
||||
fluidStack.writeToNBT(fluidStackNbt);
|
||||
fluidPacketTag.setTag("FluidStack", fluidStackNbt);
|
||||
// FluidPacket
|
||||
fluidPacketTag.setBoolean("DisplayOnly", true);
|
||||
fluidPacket.setTagCompound(fluidPacketTag);
|
||||
// Final Item
|
||||
IAEItemStack aeStack = AEItemStack.create(fluidPacket);
|
||||
aeStack.writeToNBT(fluidDisplay);
|
||||
}
|
||||
return fluidDisplay;
|
||||
}
|
||||
|
||||
public static NBTTagCompound createFluidNBT(String fluidName, long amount) {
|
||||
NBTTagCompound fluid = new NBTTagCompound();
|
||||
fluid.setString("FluidName", fluidName);
|
||||
fluid.setBoolean("Craft", false);
|
||||
fluid.setLong("Req", 0);
|
||||
fluid.setLong("Cnt", amount);
|
||||
return fluid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.glodblock.github.crossmod.extracells;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartItem;
|
||||
|
||||
public class ProxyPartItem extends ProxyItem implements IPartItem {
|
||||
|
||||
/**
|
||||
* Creates a ProxyPartItem associated with the ProxyPart instance. This instance is reused on each call to
|
||||
* {@link #createPartFromItemStack(ItemStack)}.
|
||||
*
|
||||
* @param ec2itemName extra cells internal name
|
||||
*/
|
||||
public ProxyPartItem(String ec2itemName) {
|
||||
super(ec2itemName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param srcMeta
|
||||
* @param replacement
|
||||
* @param part
|
||||
*/
|
||||
protected void addItemPart(int srcMeta, Item replacement, Function<ProxyPartItem, ProxyPart> part) {
|
||||
this.replacements.put(srcMeta, new PartReplacement(replacement, part));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IPart createPartFromItemStack(ItemStack is) {
|
||||
final int meta = is.getItemDamage();
|
||||
if (this.replacements.get(meta) instanceof PartReplacement) {
|
||||
PartReplacement part = (PartReplacement) this.replacements.get(meta);
|
||||
return part.proxyPart.apply(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Item replacement entry for ItemParts. All targets replace into 0.
|
||||
*/
|
||||
class PartReplacement extends ProxyItem.ProxyItemEntry {
|
||||
|
||||
Function<ProxyPartItem, ProxyPart> proxyPart;
|
||||
|
||||
PartReplacement(Item replacement, Function<ProxyPartItem, ProxyPart> proxyPart) {
|
||||
super(replacement, 0);
|
||||
this.proxyPart = proxyPart;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.glodblock.github.crossmod.extracells.parts;
|
||||
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPart;
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPartItem;
|
||||
|
||||
public class ProxyFluidBusIO extends ProxyPart {
|
||||
|
||||
/**
|
||||
* Map for converting slots from bus EC2 -> AE2FC
|
||||
*/
|
||||
private static int[] FILTER_MAP = null;
|
||||
|
||||
public static void init() {
|
||||
FILTER_MAP = new int[] { 5, 3, 6, 1, 0, 2, 7, 4, 8 };
|
||||
}
|
||||
|
||||
public ProxyFluidBusIO(ProxyPartItem partItem) {
|
||||
super(partItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound transformNBT(NBTTagCompound extra) {
|
||||
// Transform NBT in place
|
||||
// Fluid Filter
|
||||
NBTTagCompound fluidFilterNew = new NBTTagCompound();
|
||||
for (int slot = 0; slot < 9; ++slot) {
|
||||
String oldFilterName = "FilterFluid#" + slot;
|
||||
fluidFilterNew
|
||||
.setTag("#" + FILTER_MAP[slot], ProxyPart.createFluidDisplayTag(extra.getString(oldFilterName)));
|
||||
extra.removeTag(oldFilterName);
|
||||
}
|
||||
extra.setTag("config", fluidFilterNew);
|
||||
// Upgrades
|
||||
NBTTagList upgrades = extra.getTagList("upgradeInventory", TAG_COMPOUND);
|
||||
NBTTagCompound upgradesNew = new NBTTagCompound();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
NBTTagCompound upgrade = upgrades.getCompoundTagAt(i);
|
||||
upgrade.removeTag("Slot");
|
||||
upgradesNew.setTag("#" + i, upgrade);
|
||||
}
|
||||
extra.removeTag("upgradeInventory");
|
||||
extra.setTag("upgrades", upgradesNew);
|
||||
// Redstone mode
|
||||
RedstoneMode redstoneMode = RedstoneMode.values()[extra.getInteger("redstoneMode")];
|
||||
switch (redstoneMode) {
|
||||
case LOW_SIGNAL:
|
||||
extra.setString("REDSTONE_CONTROLLED", "LOW_SIGNAL");
|
||||
break;
|
||||
case HIGH_SIGNAL:
|
||||
extra.setString("REDSTONE_CONTROLLED", "HIGH_SIGNAL");
|
||||
break;
|
||||
case SIGNAL_PULSE:
|
||||
extra.setString("REDSTONE_CONTROLLED", "SIGNAL_PULSE");
|
||||
break;
|
||||
default:
|
||||
extra.setString("REDSTONE_CONTROLLED", "IGNORE");
|
||||
break;
|
||||
}
|
||||
extra.removeTag("redstoneMode");
|
||||
// Part data
|
||||
extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0"));
|
||||
extra.removeTag("node");
|
||||
// Extra tags
|
||||
extra.setString("CRAFT_ONLY", "NO");
|
||||
extra.setString("FUZZY_MODE", "IGNORE_ALL");
|
||||
extra.setString("SCHEDULING_MODE", "DEFAULT");
|
||||
return extra;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.glodblock.github.crossmod.extracells.parts;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPart;
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPartItem;
|
||||
|
||||
public class ProxyFluidInterface extends ProxyPart {
|
||||
|
||||
public ProxyFluidInterface(ProxyPartItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound transformNBT(NBTTagCompound extra) {
|
||||
// Internal fluids - ConfigInv and FluidInv
|
||||
NBTTagCompound tank = extra.getCompoundTag("tank");
|
||||
NBTTagCompound configTank = new NBTTagCompound();
|
||||
configTank.setTag("#0", ProxyPart.createFluidDisplayTag(tank.getString("FluidName")));
|
||||
extra.setTag("ConfigInv", configTank);
|
||||
NBTTagCompound fluidTank = new NBTTagCompound();
|
||||
NBTTagCompound fluid = ProxyPart.createFluidNBT(tank.getString("FluidName"), tank.getLong("Amount"));
|
||||
fluidTank.setTag("#0", fluid);
|
||||
extra.setTag("FluidInv", fluidTank);
|
||||
extra.removeTag("tank");
|
||||
// Patterns
|
||||
NBTTagList patterns = extra.getCompoundTag("inventory").getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
|
||||
NBTTagCompound newPatterns = new NBTTagCompound();
|
||||
for (int i = 0; i < patterns.tagCount(); ++i) {
|
||||
NBTTagCompound p = patterns.getCompoundTagAt(i);
|
||||
p.removeTag("Slot");
|
||||
newPatterns.setTag("#" + i, p);
|
||||
}
|
||||
extra.removeTag("inventory");
|
||||
extra.setTag("patterns", newPatterns);
|
||||
// Part
|
||||
extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0"));
|
||||
extra.removeTag("node");
|
||||
return extra;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.glodblock.github.crossmod.extracells.parts;
|
||||
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPart;
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPartItem;
|
||||
|
||||
public class ProxyFluidStorage extends ProxyPart {
|
||||
|
||||
private static int[] FILTER_MAP = null;
|
||||
|
||||
protected static void init() {
|
||||
// spotless:off
|
||||
FILTER_MAP = new int[] {
|
||||
0, 9, 18, 27, 36, 45,
|
||||
1, 10, 19, 28, 37, 46,
|
||||
2, 11, 20, 29, 38, 47,
|
||||
3, 12, 21, 30, 39, 48,
|
||||
4, 13, 22, 31, 40, 49,
|
||||
5, 14, 23, 32, 41, 50,
|
||||
6, 15, 24, 33, 42, 51,
|
||||
7, 16, 25, 34, 43, 52,
|
||||
8, 17, 26, 35, 44, 53 };
|
||||
//spotless:on
|
||||
}
|
||||
|
||||
public ProxyFluidStorage(ProxyPartItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound transformNBT(NBTTagCompound extra) {
|
||||
// Transform in place, less messy IMO
|
||||
// Fluid filter slots
|
||||
NBTTagCompound fluidFilterNew = new NBTTagCompound();
|
||||
for (int slot = 0; slot < 54; ++slot) {
|
||||
String oldFilterName = "FilterFluid#" + slot;
|
||||
fluidFilterNew
|
||||
.setTag("#" + FILTER_MAP[slot], ProxyPart.createFluidDisplayTag(extra.getString(oldFilterName)));
|
||||
extra.removeTag(oldFilterName);
|
||||
}
|
||||
extra.setTag("config", fluidFilterNew);
|
||||
|
||||
// Part data
|
||||
extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0"));
|
||||
extra.removeTag("node");
|
||||
|
||||
// Access
|
||||
extra.setString("ACCESS", extra.getString("access"));
|
||||
extra.removeTag("access");
|
||||
|
||||
// Upgrades
|
||||
NBTTagList upgrades = extra.getTagList("upgradeInventory", TAG_COMPOUND);
|
||||
NBTTagCompound upgradeNew = new NBTTagCompound();
|
||||
upgradeNew.setTag("#0", upgrades.getCompoundTagAt(0));
|
||||
upgradeNew.setTag("#1", new NBTTagCompound());
|
||||
upgradeNew.setTag("#2", new NBTTagCompound());
|
||||
upgradeNew.setTag("#3", new NBTTagCompound());
|
||||
upgradeNew.setTag("#4", new NBTTagCompound());
|
||||
extra.setTag("upgrades", upgradeNew);
|
||||
extra.removeTag("upgradeInventory");
|
||||
return extra;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.glodblock.github.crossmod.extracells.parts;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPart;
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPartItem;
|
||||
|
||||
public class ProxyLevelEmitter extends ProxyPart {
|
||||
|
||||
public ProxyLevelEmitter(ProxyPartItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound transformNBT(NBTTagCompound extra) {
|
||||
// Fluid
|
||||
NBTTagCompound fluidSlots = new NBTTagCompound();
|
||||
fluidSlots.setTag("#0", ProxyPart.createFluidDisplayTag(extra.getString("fluid")));
|
||||
extra.setTag("config", fluidSlots);
|
||||
extra.removeTag("fluid");
|
||||
// Redstone
|
||||
RedstoneMode redstoneMode = RedstoneMode.values()[extra.getInteger("mode")];
|
||||
if (redstoneMode == RedstoneMode.LOW_SIGNAL) {
|
||||
extra.setString("REDSTONE_EMITTER", "LOW_SIGNAL");
|
||||
} else {
|
||||
extra.setString("REDSTONE_EMITTER", "HIGH_SIGNAL");
|
||||
}
|
||||
extra.removeTag("mode");
|
||||
// Level
|
||||
long wanted = extra.getLong("wantedAmount");
|
||||
extra.setLong("reportingValue", wanted);
|
||||
extra.setLong("lastReportingValue", wanted);
|
||||
extra.removeTag("wantedAmount");
|
||||
// Part
|
||||
extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0"));
|
||||
extra.removeTag("node");
|
||||
return extra;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.glodblock.github.crossmod.extracells.parts;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPart;
|
||||
import com.glodblock.github.crossmod.extracells.ProxyPartItem;
|
||||
|
||||
public class ProxyStorageMonitor extends ProxyPart {
|
||||
|
||||
public ProxyStorageMonitor(ProxyPartItem item) {
|
||||
super(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound transformNBT(NBTTagCompound extra) {
|
||||
// Fluid
|
||||
int fluid = extra.getInteger("fluid");
|
||||
Fluid f = FluidRegistry.getFluid(fluid);
|
||||
NBTTagCompound itemDisplay = ProxyPart.createFluidNBT(f.getName(), 0L);
|
||||
extra.setTag("configuredItem", itemDisplay);
|
||||
extra.removeTag("amount");
|
||||
extra.removeTag("fluid");
|
||||
// Locked and other props
|
||||
extra.setBoolean("isLocked", extra.getBoolean("locked"));
|
||||
extra.removeTag("locked");
|
||||
extra.setByte("spin", (byte) 0);
|
||||
extra.setFloat("opacity", 255.0f);
|
||||
// Part
|
||||
extra.setTag("part", extra.getCompoundTag("node").getCompoundTag("node0"));
|
||||
extra.removeTag("node");
|
||||
return extra;
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.glodblock.github.crossmod.extracells.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ProxyExtremeStorageCell extends ProxyItemStorageCell {
|
||||
|
||||
public ProxyExtremeStorageCell(String ec2itemName) {
|
||||
super(ec2itemName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(ItemStack cellItem) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.glodblock.github.crossmod.extracells.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.exceptions.AppEngException;
|
||||
import appeng.api.storage.ISaveProvider;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
|
||||
import com.glodblock.github.common.storage.FluidCellInventory;
|
||||
|
||||
public class ProxyFluidCellInventory extends FluidCellInventory {
|
||||
|
||||
private static final String EC_CONVERTED = "ecc";
|
||||
|
||||
public ProxyFluidCellInventory(ItemStack o, ISaveProvider container) throws AppEngException {
|
||||
super(o, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadCellFluids() {
|
||||
// If we've already converted the tag to AE2FC, just go to super.
|
||||
// Else, proceed with conversion
|
||||
if (!this.tagCompound.hasKey(EC_CONVERTED)) {
|
||||
if (this.cellFluids == null) {
|
||||
this.cellFluids = AEApi.instance().storage().createFluidList();
|
||||
}
|
||||
this.cellFluids.resetStatus(); // clears totals and stuff.
|
||||
// Load using Extra Cell's NBT format
|
||||
for (int i = 0; i < this.cellType.getTotalTypes(this.cellItem); i++) {
|
||||
FluidStack fs = FluidStack.loadFluidStackFromNBT(tagCompound.getCompoundTag("Fluid#" + i));
|
||||
tagCompound.removeTag("Fluid#" + i);
|
||||
final AEFluidStack aet = AEFluidStack.create(fs);
|
||||
if (aet != null) {
|
||||
if (aet.getStackSize() > 0) {
|
||||
this.cellFluids.add(aet);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.tagCompound.setBoolean(EC_CONVERTED, true);
|
||||
// Convert to the new format
|
||||
long fluidCount = 0;
|
||||
int x = 0;
|
||||
|
||||
for (final IAEFluidStack v : this.cellFluids) {
|
||||
fluidCount += v.getStackSize();
|
||||
final NBTBase c = this.tagCompound.getTag(fluidSlots[x]);
|
||||
if (c instanceof NBTTagCompound) {
|
||||
v.writeToNBT((NBTTagCompound) c);
|
||||
} else {
|
||||
final NBTTagCompound g = new NBTTagCompound();
|
||||
v.writeToNBT(g);
|
||||
this.tagCompound.setTag(fluidSlots[x], g);
|
||||
}
|
||||
this.tagCompound.setLong(fluidSlotCount[x], v.getStackSize());
|
||||
x++;
|
||||
}
|
||||
this.storedFluids = (short) this.cellFluids.size();
|
||||
|
||||
if (!this.cellFluids.isEmpty()) {
|
||||
this.tagCompound.setShort(FLUID_TYPE_TAG, this.storedFluids);
|
||||
}
|
||||
|
||||
this.storedFluidCount = fluidCount;
|
||||
if (fluidCount > 0) {
|
||||
this.tagCompound.setLong(FLUID_COUNT_TAG, fluidCount);
|
||||
}
|
||||
} else {
|
||||
super.loadCellFluids();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package com.glodblock.github.crossmod.extracells.storage;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import com.glodblock.github.common.Config;
|
||||
import com.glodblock.github.common.storage.IStorageFluidCell;
|
||||
import com.glodblock.github.crossmod.extracells.ProxyItem;
|
||||
import com.glodblock.github.util.ModAndClassUtil;
|
||||
|
||||
public class ProxyFluidStorageCell extends ProxyItem implements IStorageFluidCell {
|
||||
|
||||
public ProxyFluidStorageCell(String ec2itemName) {
|
||||
super(ec2itemName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBytes(ItemStack cellItem) {
|
||||
int meta = cellItem.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return ((ProxyStorageEntry) entry).maxBytes;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytesPerType(ItemStack cellItem) {
|
||||
int meta = cellItem.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return ((ProxyStorageEntry) entry).bytesPerType;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition) {
|
||||
if (Config.blacklistEssentiaGas && ModAndClassUtil.ThE && requestedAddition != null) {
|
||||
return ModAndClassUtil.essentiaGas.isInstance(requestedAddition.getFluid());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell(ItemStack i) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain(ItemStack is) {
|
||||
int meta = is.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return ((ProxyStorageEntry) entry).idleDrain;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(ItemStack cellItem) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory(ItemStack is) {
|
||||
return new CellUpgrades(is, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory(ItemStack is) {
|
||||
return new CellConfig(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(ItemStack is) {
|
||||
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
|
||||
try {
|
||||
return FuzzyMode.valueOf(fz);
|
||||
} catch (final Throwable t) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.glodblock.github.crossmod.extracells.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.core.features.registries.entries.BasicCellHandler;
|
||||
|
||||
public class ProxyItemCellHandler extends BasicCellHandler {
|
||||
|
||||
@Override
|
||||
public boolean isCell(ItemStack is) {
|
||||
return is != null && is.getItem() != null && is.getItem() instanceof ProxyItemStorageCell;
|
||||
}
|
||||
}
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
package com.glodblock.github.crossmod.extracells.storage;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.implementations.items.IStorageCell;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.items.contents.CellConfig;
|
||||
import appeng.items.contents.CellUpgrades;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import com.glodblock.github.crossmod.extracells.ProxyItem;
|
||||
|
||||
/**
|
||||
* Proxy Item Storage. 256K, 1024K, etc. -> AE2's version. For now its just mirroring AE2's version, will need to
|
||||
* transition to something better.
|
||||
*/
|
||||
public class ProxyItemStorageCell extends ProxyItem implements IStorageCell {
|
||||
|
||||
public ProxyItemStorageCell(String ec2itemName) {
|
||||
super(ec2itemName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(ItemStack cellItem) {
|
||||
if (cellItem == null) {
|
||||
return 0;
|
||||
}
|
||||
int meta = cellItem.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return (int) ((ProxyStorageEntry) entry).maxBytes;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int BytePerType(ItemStack cellItem) {
|
||||
if (cellItem == null) {
|
||||
return 0;
|
||||
}
|
||||
int meta = cellItem.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return ((ProxyStorageEntry) entry).bytesPerType;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytesPerType(ItemStack cellItem) {
|
||||
if (cellItem == null) {
|
||||
return 0;
|
||||
}
|
||||
int meta = cellItem.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return ((ProxyStorageEntry) entry).bytesPerType;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBytesLong(ItemStack cellItem) {
|
||||
if (cellItem == null) {
|
||||
return 0;
|
||||
}
|
||||
int meta = cellItem.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return ((ProxyStorageEntry) entry).maxBytes;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalTypes(ItemStack cellItem) {
|
||||
return 63;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlackListed(ItemStack cellItem, IAEItemStack requestedAddition) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean storableInStorageCell() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageCell(ItemStack i) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain(@Nullable ItemStack cellItem) {
|
||||
if (cellItem == null) {
|
||||
return 0.0;
|
||||
}
|
||||
int meta = cellItem.getItemDamage();
|
||||
if (replacements.containsKey(meta)) {
|
||||
ProxyItemEntry entry = replacements.get(meta);
|
||||
if (entry instanceof ProxyStorageEntry) {
|
||||
return ((ProxyStorageEntry) entry).bytesPerType;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getIdleDrain() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEditable(ItemStack is) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory(ItemStack is) {
|
||||
return new CellUpgrades(is, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory(ItemStack is) {
|
||||
return new CellConfig(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FuzzyMode getFuzzyMode(ItemStack is) {
|
||||
final String fz = Platform.openNbtData(is).getString("FuzzyMode");
|
||||
try {
|
||||
return FuzzyMode.valueOf(fz);
|
||||
} catch (final Throwable t) {
|
||||
return FuzzyMode.IGNORE_ALL;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {
|
||||
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOreFilter(ItemStack is) {
|
||||
return Platform.openNbtData(is).getString("OreFilter");
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.glodblock.github.crossmod.extracells.storage;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.core.features.registries.entries.VoidCellHandler;
|
||||
|
||||
public class ProxyVoidCellHandler extends VoidCellHandler {
|
||||
|
||||
@Override
|
||||
public boolean isCell(ItemStack is) {
|
||||
return is != null && is.getItem() != null && is.getItem() instanceof ProxyVoidStorageCell;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.glodblock.github.crossmod.extracells.storage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.items.storage.ItemVoidStorageCell;
|
||||
|
||||
public class ProxyVoidStorageCell extends ItemVoidStorageCell {
|
||||
|
||||
private final String name = AEApi.instance().definitions().items().cellVoid().maybeStack(1).get()
|
||||
.getUnlocalizedName();
|
||||
|
||||
@Override
|
||||
public void addCheckedInformation(ItemStack stack, EntityPlayer player, List<String> info,
|
||||
boolean displayMoreInfo) {
|
||||
info.add(EnumChatFormatting.RED + "Extra Cells Placeholder for:");
|
||||
info.add(EnumChatFormatting.AQUA + name);
|
||||
info.add(EnumChatFormatting.GOLD + "Put in your inventory to get a replacement.");
|
||||
info.add(EnumChatFormatting.GOLD + "It will disappear if no replacement was found.");
|
||||
info.add(EnumChatFormatting.RED + "Report missing conversions on the Github.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int p_77663_4_, boolean p_77663_5_) {
|
||||
if (!worldIn.isRemote && entityIn instanceof EntityPlayer) {
|
||||
EntityPlayer player = (EntityPlayer) entityIn;
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); ++i) {
|
||||
ItemStack s = player.inventory.getStackInSlot(i);
|
||||
if (s == stack) {
|
||||
ItemStack replaceStack = AEApi.instance().definitions().items().cellVoid().maybeStack(1).get();
|
||||
player.inventory.setInventorySlotContents(i, replaceStack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -278,9 +278,15 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new SlotIterator(
|
||||
invFluids != null ? invFluids.getTankInfo(side) : new FluidTankInfo[0],
|
||||
invItems != null ? invItems.iterator() : Collections.emptyIterator());
|
||||
FluidTankInfo[] info = null;
|
||||
if (invFluids != null) {
|
||||
info = invFluids.getTankInfo(side);
|
||||
}
|
||||
// Null check is needed because some tank infos return null (EIO conduits...)
|
||||
if (info == null) {
|
||||
info = new FluidTankInfo[0];
|
||||
}
|
||||
return new SlotIterator(info, invItems != null ? invItems.iterator() : Collections.emptyIterator());
|
||||
}
|
||||
|
||||
private IFluidHandler getSideFluid(ForgeDirection direction) {
|
||||
@@ -466,7 +472,7 @@ public class FluidConvertingInventoryAdaptor extends InventoryAdaptor {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return nextSlotIndex < tanks.length || itemSlots.hasNext();
|
||||
return itemSlots.hasNext() || nextSlotIndex < tanks.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ItemAndBlockHolder {
|
||||
NameConst.ITEM_QUANTUM_FLUID_STORAGE,
|
||||
Integer.MAX_VALUE / 16,
|
||||
8,
|
||||
5,
|
||||
1,
|
||||
4.5).register();
|
||||
public static ItemFluidExtremeStorageCell SINGULARITY_CELL = new ItemFluidExtremeStorageCell(
|
||||
NameConst.ITEM_SINGULARITY_FLUID_STORAGE,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,7 +38,7 @@ public class SPacketMEFluidInvUpdate implements IMessage {
|
||||
|
||||
/**
|
||||
* If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet
|
||||
* should resort.
|
||||
* should resort
|
||||
*
|
||||
* @param resort whether this packet should resort the term or not
|
||||
*/
|
||||
@@ -51,13 +50,14 @@ public class SPacketMEFluidInvUpdate implements IMessage {
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ref = buf.readByte();
|
||||
resort = buf.readBoolean();
|
||||
long amount = buf.readLong();
|
||||
list = new ArrayList<>();
|
||||
int amount = buf.readInt();
|
||||
list = new ArrayList<>(amount);
|
||||
try {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
list.add(AEFluidStack.loadFluidStackFromPacket(buf));
|
||||
}
|
||||
} catch (IOException io) {
|
||||
} catch (Exception io) {
|
||||
System.out.println("Error handling payload w/ " + amount + " items.");
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class SPacketMEFluidInvUpdate implements IMessage {
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(ref);
|
||||
buf.writeBoolean(resort);
|
||||
buf.writeLong(list.size());
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (IAEFluidStack is : list) {
|
||||
is.writeToPacket(buf);
|
||||
@@ -80,7 +80,7 @@ public class SPacketMEFluidInvUpdate implements IMessage {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
public void appendFluid(final IAEFluidStack is) throws BufferOverflowException {
|
||||
public void appendFluid(final IAEFluidStack is) {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.glodblock.github.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -36,13 +35,12 @@ public class SPacketMEItemInvUpdate implements IMessage {
|
||||
*/
|
||||
public SPacketMEItemInvUpdate(byte b) {
|
||||
ref = b;
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* If resort, call "updateView()". Used when multiple packets are sent to open an inventory; only the last packet
|
||||
* should resort.
|
||||
*
|
||||
*
|
||||
* @param resort whether this packet should resort the term or not
|
||||
*/
|
||||
public SPacketMEItemInvUpdate(boolean resort) {
|
||||
@@ -53,13 +51,14 @@ public class SPacketMEItemInvUpdate implements IMessage {
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
ref = buf.readByte();
|
||||
resort = buf.readBoolean();
|
||||
long amount = buf.readLong();
|
||||
list = new ArrayList<>();
|
||||
int amount = buf.readInt();
|
||||
list = new ArrayList<>(amount);
|
||||
try {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
list.add(AEItemStack.loadItemStackFromPacket(buf));
|
||||
}
|
||||
} catch (IOException io) {
|
||||
} catch (Exception io) {
|
||||
System.out.println("Error handling payload w/ " + amount + " items.");
|
||||
io.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -68,7 +67,7 @@ public class SPacketMEItemInvUpdate implements IMessage {
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeByte(ref);
|
||||
buf.writeBoolean(resort);
|
||||
buf.writeLong(list.size());
|
||||
buf.writeInt(list.size());
|
||||
try {
|
||||
for (IAEItemStack is : list) {
|
||||
is.writeToPacket(buf);
|
||||
@@ -82,7 +81,7 @@ public class SPacketMEItemInvUpdate implements IMessage {
|
||||
this.resort = resort;
|
||||
}
|
||||
|
||||
public void appendItem(final IAEItemStack is) throws BufferOverflowException {
|
||||
public void appendItem(final IAEItemStack is) {
|
||||
list.add(is);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,18 +12,22 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.Config;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
/**
|
||||
* Only should exist on the server side!
|
||||
* Only should exist on the server side! Schedules packets to be sent every `packetRate` ms.
|
||||
*/
|
||||
public class SPacketMEUpdateBuffer {
|
||||
|
||||
private static ScheduledExecutorService executor;
|
||||
private static ScheduledFuture<?> task;
|
||||
|
||||
private static final Map<EntityPlayerMP, LinkedHashMap<IAEItemStack, IAEItemStack>> itemBuffer = new HashMap<>();
|
||||
private static final Map<EntityPlayerMP, LinkedHashSet<IAEItemStack>> itemBuffer = new HashMap<>();
|
||||
|
||||
private static final Map<EntityPlayerMP, Map<IAEFluidStack, IAEFluidStack>> fluidBuffer = new HashMap<>();
|
||||
private static final Map<EntityPlayerMP, LinkedHashSet<IAEFluidStack>> fluidBuffer = new HashMap<>();
|
||||
|
||||
public static void init() {
|
||||
executor = Executors.newSingleThreadScheduledExecutor(r -> {
|
||||
@@ -33,7 +37,8 @@ public class SPacketMEUpdateBuffer {
|
||||
thread.setPriority(6);
|
||||
return thread;
|
||||
});
|
||||
task = executor.scheduleAtFixedRate(SPacketMEUpdateBuffer::sendBuffer, 0, 50, TimeUnit.MILLISECONDS);
|
||||
task = executor
|
||||
.scheduleAtFixedRate(SPacketMEUpdateBuffer::sendBuffer, 0, Config.packetRate, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public static void disable() {
|
||||
@@ -44,20 +49,20 @@ public class SPacketMEUpdateBuffer {
|
||||
public static void scheduleItemUpdate(EntityPlayerMP player, List<IAEItemStack> stacks) {
|
||||
synchronized (itemBuffer) {
|
||||
if (!itemBuffer.containsKey(player)) {
|
||||
itemBuffer.put(player, new LinkedHashMap<>(1024));
|
||||
itemBuffer.put(player, new LinkedHashSet<>(1024));
|
||||
}
|
||||
Map<IAEItemStack, IAEItemStack> buffer = itemBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.put(s, s));
|
||||
LinkedHashSet<IAEItemStack> buffer = itemBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.add(s.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void scheduleFluidUpdate(EntityPlayerMP player, List<IAEFluidStack> stacks) {
|
||||
synchronized (itemBuffer) {
|
||||
if (!fluidBuffer.containsKey(player)) {
|
||||
fluidBuffer.put(player, new LinkedHashMap<>(1024));
|
||||
fluidBuffer.put(player, new LinkedHashSet<>(1024));
|
||||
}
|
||||
Map<IAEFluidStack, IAEFluidStack> buffer = fluidBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.put(s, s));
|
||||
LinkedHashSet<IAEFluidStack> buffer = fluidBuffer.get(player);
|
||||
stacks.forEach(s -> buffer.add(s.copy()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,35 +71,39 @@ public class SPacketMEUpdateBuffer {
|
||||
itemBuffer.forEach((player, updates) -> {
|
||||
if (updates.isEmpty()) return;
|
||||
int i = 0;
|
||||
SPacketMEItemInvUpdate packet = new SPacketMEItemInvUpdate();
|
||||
Iterator<IAEItemStack> it = updates.keySet().iterator();
|
||||
SPacketMEItemInvUpdate packet = new SPacketMEItemInvUpdate(false);
|
||||
Iterator<IAEItemStack> it = updates.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (i < 256) {
|
||||
if (i < Config.packetSize) {
|
||||
packet.appendItem(it.next());
|
||||
it.remove();
|
||||
i++;
|
||||
} else {
|
||||
packet.setResort(false);
|
||||
break;
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
packet = new SPacketMEItemInvUpdate(false);
|
||||
i = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
packet.setResort(true);
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
});
|
||||
fluidBuffer.forEach((player, updates) -> {
|
||||
if (updates.isEmpty()) return;
|
||||
int i = 0;
|
||||
SPacketMEFluidInvUpdate packet = new SPacketMEFluidInvUpdate();
|
||||
Iterator<IAEFluidStack> it = updates.keySet().iterator();
|
||||
SPacketMEFluidInvUpdate packet = new SPacketMEFluidInvUpdate(false);
|
||||
Iterator<IAEFluidStack> it = updates.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (i < 256) {
|
||||
if (i < Config.packetSize) {
|
||||
packet.appendFluid(it.next());
|
||||
it.remove();
|
||||
i++;
|
||||
} else {
|
||||
packet.setResort(false);
|
||||
break;
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
packet = new SPacketMEFluidInvUpdate(false);
|
||||
i = 0;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
packet.setResort(true);
|
||||
FluidCraft.proxy.netHandler.sendTo(packet, player);
|
||||
});
|
||||
|
||||
@@ -111,4 +120,11 @@ public class SPacketMEUpdateBuffer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event) {
|
||||
if (event.player instanceof EntityPlayerMP) {
|
||||
clear((EntityPlayerMP) event.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,13 @@ import appeng.api.config.Upgrades;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.Config;
|
||||
import com.glodblock.github.common.tile.TileWalrus;
|
||||
import com.glodblock.github.crossmod.extracells.EC2Replacer;
|
||||
import com.glodblock.github.inventory.external.AEFluidInterfaceHandler;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.network.SPacketMEUpdateBuffer;
|
||||
import com.glodblock.github.util.ModAndClassUtil;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -27,6 +30,10 @@ public class CommonProxy {
|
||||
|
||||
public void init(FMLInitializationEvent event) {
|
||||
this.registerMovables();
|
||||
FMLCommonHandler.instance().bus().register(SPacketMEUpdateBuffer.class);
|
||||
if (!ModAndClassUtil.EC2 && Config.replaceEC2) {
|
||||
EC2Replacer.initReplacer();
|
||||
}
|
||||
}
|
||||
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
||||
Reference in new issue
Block a user