Merge pull request #2443 from KellenHurrey/master

Some RBMK OC integration
This commit is contained in:
HbmMods 2025-09-21 21:04:09 +02:00 committed by GitHub
commit 7285867856
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 73 additions and 42 deletions

View File

@ -25,12 +25,10 @@ import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.*;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Arguments;
@ -631,6 +629,15 @@ public class TileEntityRBMKConsole extends TileEntityMachineBase implements ICon
TileEntityRBMKOutgasser irradiationChannel = (TileEntityRBMKOutgasser)te; TileEntityRBMKOutgasser irradiationChannel = (TileEntityRBMKOutgasser)te;
data_table.put("fluxProgress", irradiationChannel.progress); data_table.put("fluxProgress", irradiationChannel.progress);
data_table.put("requiredFlux", irradiationChannel.duration); data_table.put("requiredFlux", irradiationChannel.duration);
ItemStack input = irradiationChannel.getStackInSlot(0);
if (input != null){
data_table.put("craftingName", input.getUnlocalizedName());
data_table.put("craftingNumber", input.stackSize);
}
else {
data_table.put("craftingName", "");
data_table.put("craftingNumber", 0);
}
} }
if(te instanceof TileEntityRBMKHeater){ if(te instanceof TileEntityRBMKHeater){
@ -760,6 +767,7 @@ public class TileEntityRBMKConsole extends TileEntityMachineBase implements ICon
@Callback(direct = true) @Callback(direct = true)
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] pressAZ5(Context context, Arguments args) { public Object[] pressAZ5(Context context, Arguments args) {
worldObj.playSoundEffect(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5,"hbm:block.shutdown",1.0F, 1.0F);
boolean hasRods = false; boolean hasRods = false;
for(int i = -7; i <= 7; i++) { for(int i = -7; i <= 7; i++) {
for(int j = -7; j <= 7; j++) { for(int j = -7; j <= 7; j++) {

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[] { "", 0 };
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) {
@ -282,7 +291,11 @@ public class TileEntityRBMKOutgasser extends TileEntityRBMKSlottedBase implement
@Callback(direct = true) @Callback(direct = true)
@Optional.Method(modid = "OpenComputers") @Optional.Method(modid = "OpenComputers")
public Object[] getInfo(Context context, Arguments args) { public Object[] getInfo(Context context, Arguments args) {
return new Object[] {gas.getFill(), gas.getMaxFill(), progress, gas.getTankType().getID(), xCoord, yCoord, zCoord}; ItemStack input = slots[0];
if (input != null)
return new Object[] {gas.getFill(), gas.getMaxFill(), progress, gas.getTankType().getID(), xCoord, yCoord, zCoord, input.getUnlocalizedName(), input.stackSize };
else
return new Object[] {gas.getFill(), gas.getMaxFill(), progress, gas.getTankType().getID(), xCoord, yCoord, zCoord, "", 0 };
} }
@Override @Override

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);
} }