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() { public String getName() {
return "container.rbmkOutgasser"; return "container.rbmkOutgasser";
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if(!worldObj.isRemote) { if(!worldObj.isRemote) {
if(!canProcess()) { if(!canProcess()) {
this.progress = 0; this.progress = 0;
} }
for(DirPos pos : getOutputPos()) { for(DirPos pos : getOutputPos()) {
if(this.gas.getFill() > 0) this.sendFluid(gas, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); if(this.gas.getFill() > 0) this.sendFluid(gas, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
} }
} }
super.updateEntity(); super.updateEntity();
} }
protected DirPos[] getOutputPos() { protected DirPos[] getOutputPos() {
if(worldObj.getBlock(xCoord, yCoord - 1, zCoord) == ModBlocks.rbmk_loader) { if(worldObj.getBlock(xCoord, yCoord - 1, zCoord) == ModBlocks.rbmk_loader) {
return new DirPos[] { return new DirPos[] {
new DirPos(this.xCoord, this.yCoord + RBMKDials.getColumnHeight(worldObj) + 1, this.zCoord, Library.POS_Y), 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 @Override
public void receiveFlux(NeutronStream stream) { public void receiveFlux(NeutronStream stream) {
if(canProcess()) { if(canProcess()) {
double efficiency = Math.min(1 - stream.fluxRatio * 0.8, 1); double efficiency = Math.min(1 - stream.fluxRatio * 0.8, 1);
progress += stream.fluxQuantity * efficiency * RBMKDials.getOutgasserMod(worldObj); progress += stream.fluxQuantity * efficiency * RBMKDials.getOutgasserMod(worldObj);
if(progress > duration) { if(progress > duration) {
process(); process();
this.markDirty(); this.markDirty();
} }
} }
} }
public boolean canProcess() { public boolean canProcess() {
if(slots[0] == null) if(slots[0] == null)
return false; return false;
Pair<ItemStack, FluidStack> output = OutgasserRecipes.getOutput(slots[0]); Pair<ItemStack, FluidStack> output = OutgasserRecipes.getOutput(slots[0]);
if(output == null) if(output == null)
return false; return false;
FluidStack fluid = output.getValue(); FluidStack fluid = output.getValue();
if(fluid != null) { if(fluid != null) {
@ -125,27 +125,27 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
gas.setTankType(fluid.type); gas.setTankType(fluid.type);
if(gas.getFill() + fluid.fill > gas.getMaxFill()) return false; if(gas.getFill() + fluid.fill > gas.getMaxFill()) return false;
} }
ItemStack out = output.getKey(); ItemStack out = output.getKey();
if(slots[1] == null || out == null) if(slots[1] == null || out == null)
return true; return true;
return slots[1].getItem() == out.getItem() && slots[1].getItemDamage() == out.getItemDamage() && slots[1].stackSize + out.stackSize <= slots[1].getMaxStackSize(); return slots[1].getItem() == out.getItem() && slots[1].getItemDamage() == out.getItemDamage() && slots[1].stackSize + out.stackSize <= slots[1].getMaxStackSize();
} }
private void process() { private void process() {
Pair<ItemStack, FluidStack> output = OutgasserRecipes.getOutput(slots[0]); Pair<ItemStack, FluidStack> output = OutgasserRecipes.getOutput(slots[0]);
this.decrStackSize(0, 1); this.decrStackSize(0, 1);
this.progress = 0; this.progress = 0;
if(output.getValue() != null) { if(output.getValue() != null) {
gas.setFill(gas.getFill() + output.getValue().fill); gas.setFill(gas.getFill() + output.getValue().fill);
} }
ItemStack out = output.getKey(); ItemStack out = output.getKey();
if(out != null) { if(out != null) {
if(slots[1] == null) { if(slots[1] == null) {
slots[1] = out.copy(); slots[1] = out.copy();
@ -154,16 +154,16 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
} }
} }
} }
@Override @Override
public void onMelt(int reduce) { public void onMelt(int reduce) {
int count = 4 + worldObj.rand.nextInt(2); int count = 4 + worldObj.rand.nextInt(2);
for(int i = 0; i < count; i++) { for(int i = 0; i < count; i++) {
spawnDebris(DebrisType.BLANK); spawnDebris(DebrisType.BLANK);
} }
super.onMelt(reduce); super.onMelt(reduce);
} }
@ -186,19 +186,19 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
data.setDouble("progress", this.progress); data.setDouble("progress", this.progress);
return data; return data;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.progress = nbt.getDouble("progress"); this.progress = nbt.getDouble("progress");
this.gas.readFromNBT(nbt, "gas"); this.gas.readFromNBT(nbt, "gas");
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setDouble("progress", this.progress); nbt.setDouble("progress", this.progress);
this.gas.writeToNBT(nbt, "gas"); this.gas.writeToNBT(nbt, "gas");
} }
@ -260,7 +260,7 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
public Object[] getGasMax(Context context, Arguments args) { public Object[] getGasMax(Context context, Arguments args) {
return new Object[] {gas.getMaxFill()}; return new Object[] {gas.getMaxFill()};
} }
@Callback(direct = true) @Callback(direct = true)
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getGasType(Context context, Arguments args) { public Object[] getGasType(Context context, Arguments args) {
@ -273,6 +273,15 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
return new Object[] {progress}; 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) @Callback(direct = true)
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getCoordinates(Context context, Arguments args) { 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 com.hbm.tileentity.IGUIProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; 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 * 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 * those things Yes it's a copy pasted MachineBase class, thank the lack of
* multiple inheritance for that * multiple inheritance for that
* *
* @author hbm * @author hbm
* *
*/ */
@ -87,6 +88,15 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
return false; 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 @Override
public ItemStack decrStackSize(int slot, int amount) { public ItemStack decrStackSize(int slot, int amount) {
if(slots[slot] != null) { if(slots[slot] != null) {
@ -124,10 +134,10 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
if(!diag) { if(!diag) {
NBTTagList list = nbt.getTagList("items", 10); NBTTagList list = nbt.getTagList("items", 10);
for(int i = 0; i < list.tagCount(); i++) { for(int i = 0; i < list.tagCount(); i++) {
NBTTagCompound nbt1 = list.getCompoundTagAt(i); NBTTagCompound nbt1 = list.getCompoundTagAt(i);
byte b0 = nbt1.getByte("slot"); byte b0 = nbt1.getByte("slot");
@ -143,10 +153,10 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
@Override @Override
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
if(!diag) { if(!diag) {
NBTTagList list = new NBTTagList(); NBTTagList list = new NBTTagList();
for(int i = 0; i < slots.length; i++) { for(int i = 0; i < slots.length; i++) {
if(slots[i] != null) { if(slots[i] != null) {
NBTTagCompound nbt1 = new NBTTagCompound(); NBTTagCompound nbt1 = new NBTTagCompound();
@ -156,7 +166,7 @@ public abstract class TileEntityRBMKSlottedBase extends TileEntityRBMKActiveBase
} }
} }
nbt.setTag("items", list); nbt.setTag("items", list);
if (customName != null) { if (customName != null) {
nbt.setString("name", customName); nbt.setString("name", customName);
} }