Make RBMK slotted elements have OC accessible inventories, and added a OC outgasser function that allows seeing the item that is being processed.

This commit is contained in:
Kellen Hurrey 2025-09-19 10:51:32 -06:00
parent f6c74ce98e
commit ebd7ffc827
No known key found for this signature in database
GPG Key ID: CF1E5CF3DB06C0D3
2 changed files with 56 additions and 37 deletions

View File

@ -46,26 +46,26 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
public String getName() {
return "container.rbmkOutgasser";
}
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
if(!canProcess()) {
this.progress = 0;
}
for(DirPos pos : getOutputPos()) {
if(this.gas.getFill() > 0) this.sendFluid(gas, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
}
}
super.updateEntity();
}
protected DirPos[] getOutputPos() {
if(worldObj.getBlock(xCoord, yCoord - 1, zCoord) == ModBlocks.rbmk_loader) {
return new DirPos[] {
new DirPos(this.xCoord, this.yCoord + RBMKDials.getColumnHeight(worldObj) + 1, this.zCoord, Library.POS_Y),
@ -94,30 +94,30 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
@Override
public void receiveFlux(NeutronStream stream) {
if(canProcess()) {
double efficiency = Math.min(1 - stream.fluxRatio * 0.8, 1);
progress += stream.fluxQuantity * efficiency * RBMKDials.getOutgasserMod(worldObj);
if(progress > duration) {
process();
this.markDirty();
}
}
}
public boolean canProcess() {
if(slots[0] == null)
return false;
Pair<ItemStack, FluidStack> output = OutgasserRecipes.getOutput(slots[0]);
if(output == null)
return false;
FluidStack fluid = output.getValue();
if(fluid != null) {
@ -125,27 +125,27 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
gas.setTankType(fluid.type);
if(gas.getFill() + fluid.fill > gas.getMaxFill()) return false;
}
ItemStack out = output.getKey();
if(slots[1] == null || out == null)
return true;
return slots[1].getItem() == out.getItem() && slots[1].getItemDamage() == out.getItemDamage() && slots[1].stackSize + out.stackSize <= slots[1].getMaxStackSize();
}
private void process() {
Pair<ItemStack, FluidStack> output = OutgasserRecipes.getOutput(slots[0]);
this.decrStackSize(0, 1);
this.progress = 0;
if(output.getValue() != null) {
gas.setFill(gas.getFill() + output.getValue().fill);
}
ItemStack out = output.getKey();
if(out != null) {
if(slots[1] == null) {
slots[1] = out.copy();
@ -154,16 +154,16 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
}
}
}
@Override
public void onMelt(int reduce) {
int count = 4 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.BLANK);
}
super.onMelt(reduce);
}
@ -186,19 +186,19 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
data.setDouble("progress", this.progress);
return data;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.progress = nbt.getDouble("progress");
this.gas.readFromNBT(nbt, "gas");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setDouble("progress", this.progress);
this.gas.writeToNBT(nbt, "gas");
}
@ -260,7 +260,7 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
public Object[] getGasMax(Context context, Arguments args) {
return new Object[] {gas.getMaxFill()};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getGasType(Context context, Arguments args) {
@ -273,6 +273,15 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
return new Object[] {progress};
}
@Callback(direct = true, doc = "Returns the unlocalized name and size of the stack that the outgasser is crafting (the input), or nil, nil if there is no stack")
@Optional.Method(modid = "OpenComputers")
public Object[] getCrafting(Context context, Arguments args) {
if (slots[0] == null)
return new Object[] { null, null };
else
return new Object[]{slots[0].getUnlocalizedName(), slots[0].stackSize};
}
@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getCoordinates(Context context, Arguments args) {

View File

@ -2,6 +2,7 @@ package com.hbm.tileentity.machine.rbmk;
import com.hbm.tileentity.IGUIProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -11,7 +12,7 @@ import net.minecraft.nbt.NBTTagList;
* Base class for RBMK components that have GUI slots and thus have to handle
* those things Yes it's a copy pasted MachineBase class, thank the lack of
* multiple inheritance for that
*
*
* @author hbm
*
*/
@ -87,6 +88,15 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
return false;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) {
return false;
} else {
return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 128;
}
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
if(slots[slot] != null) {
@ -124,10 +134,10 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
if(!diag) {
NBTTagList list = nbt.getTagList("items", 10);
for(int i = 0; i < list.tagCount(); i++) {
NBTTagCompound nbt1 = list.getCompoundTagAt(i);
byte b0 = nbt1.getByte("slot");
@ -143,10 +153,10 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
if(!diag) {
NBTTagList list = new NBTTagList();
for(int i = 0; i < slots.length; i++) {
if(slots[i] != null) {
NBTTagCompound nbt1 = new NBTTagCompound();
@ -156,7 +166,7 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
}
}
nbt.setTag("items", list);
if (customName != null) {
nbt.setString("name", customName);
}