Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vent carbon dioxide function in Zirnox for OpenComputers #1873

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC
public FluidTank carbonDioxide;
public FluidTank water;
protected int output;

private static final int[] slots_io = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };

public static final HashMap<ComparableStack, ItemStack> fuelMap = new HashMap<ComparableStack, ItemStack>();
Expand Down Expand Up @@ -89,7 +89,7 @@ public TileEntityReactorZirnox() {
public String getName() {
return "container.zirnox";
}

@Override
public int[] getAccessibleSlotsFromSide(int side) {
return slots_io;
Expand Down Expand Up @@ -156,7 +156,7 @@ private int[] getNeighbouringSlots(int id) {
case 11: return new int[] { 4, 10, 12, 18 };
case 12: return new int[] { 5, 11, 13, 19 };
case 13: return new int[] { 6, 12, 20 };
case 14: return new int[] { 7, 15, 21 };
case 14: return new int[] { 7, 15, 21 };
case 15: return new int[] { 8, 14, 16, 22 };
case 16: return new int[] { 9, 15, 23 };
case 17: return new int[] { 10, 18 };
Expand All @@ -177,14 +177,14 @@ public void updateEntity() {
if(!worldObj.isRemote) {

this.output = 0;

if(worldObj.getTotalWorldTime() % 20 == 0) {
this.updateConnections();
}

carbonDioxide.loadTank(24, 26, slots);
water.loadTank(25, 27, slots);

if(isOn) {
for(int i = 0; i < 24; i++) {

Expand All @@ -196,7 +196,7 @@ else if(slots[i].getItem() == ModItems.meteorite_sword_bred)
}
}
}

//2(fill) + (x * fill%)
this.pressure = (this.carbonDioxide.getFill() * 2) + (int)((float)this.heat * ((float)this.carbonDioxide.getFill() / (float)this.carbonDioxide.getMaxFill()));

Expand All @@ -208,9 +208,9 @@ else if(slots[i].getItem() == ModItems.meteorite_sword_bred)
} else {
this.heat -= 10;
}

}

for(DirPos pos : getConPos()) {
this.sendFluid(steam, worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
}
Expand Down Expand Up @@ -244,16 +244,16 @@ public void deserialize(ByteBuf buf) {
}

private void generateSteam() {

// function of SHS produced per tick
// (heat - 10256)/100000 * steamFill (max efficiency at 14b) * 25 * 5 (should get rid of any rounding errors)
if(this.heat > 10256) {
int cycle = (int)((((float)heat - 10256F) / (float)maxHeat) * Math.min(((float)carbonDioxide.getFill() / 14000F), 1F) * 25F * 5F);
this.output = cycle;

water.setFill(water.getFill() - cycle);
steam.setFill(steam.getFill() + cycle);

if(water.getFill() < 0)
water.setFill(0);

Expand Down Expand Up @@ -301,7 +301,7 @@ private void decay(int id) {
for(int i = 0; i < decay; i++) {
this.heat += num.heat;
ItemZirnoxRod.incrementLifeTime(slots[id]);

if(ItemZirnoxRod.getLifeTime(slots[id]) > num.maxLife) {
slots[id] = fuelMap.get(new ComparableStack(getStackInSlot(id))).copy();
break;
Expand Down Expand Up @@ -338,16 +338,16 @@ private void spawnDebris(DebrisType type) {
}

private void zirnoxDebris() {

for(int i = 0; i < 2; i++) {
spawnDebris(DebrisType.EXCHANGER);
}

for(int i = 0; i < 20; i++) {
spawnDebris(DebrisType.CONCRETE);
spawnDebris(DebrisType.BLANK);
}

for(int i = 0; i < 10; i++) {
spawnDebris(DebrisType.ELEMENT);
spawnDebris(DebrisType.GRAPHITE);
Expand All @@ -369,14 +369,14 @@ private void meltdown() {
worldObj.createExplosion(null, this.xCoord, this.yCoord + 3, this.zCoord, 12.0F, true);
zirnoxDebris();
ExplosionNukeGeneric.waste(worldObj, this.xCoord, this.yCoord, this.zCoord, 35);

List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class,
AxisAlignedBB.getBoundingBox(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5).expand(100, 100, 100));

for(EntityPlayer player : players) {
player.triggerAchievement(MainRegistry.achZIRNOXBoom);
}

if(MobConfig.enableElementals) {
for(EntityPlayer player : players) {
player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG).setBoolean("radMark", true);
Expand All @@ -390,11 +390,11 @@ private void updateConnections() {
this.trySubscribe(carbonDioxide.getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir());
}
}

private DirPos[] getConPos() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.UP);

return new DirPos[] {
new DirPos(this.xCoord + rot.offsetX * 3, this.yCoord + 1, this.zCoord + rot.offsetZ * 3, rot),
new DirPos(this.xCoord + rot.offsetX * 3, this.yCoord + 3, this.zCoord + rot.offsetZ * 3, rot),
Expand All @@ -420,25 +420,25 @@ public AxisAlignedBB getRenderBoundingBox() {
public double getMaxRenderDistanceSquared() {
return 65536.0D;
}

@Override
public boolean hasPermission(EntityPlayer player) {
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
}

@Override
public void receiveControl(NBTTagCompound data) {
if(data.hasKey("control")) {
this.isOn = !this.isOn;
}

if(data.hasKey("vent")) {
int fill = this.carbonDioxide.getFill();
this.carbonDioxide.setFill(fill - 1000);
if(this.carbonDioxide.getFill() < 0)
this.carbonDioxide.setFill(0);
}

this.markDirty();
}

Expand All @@ -456,7 +456,7 @@ public FluidTank[] getReceivingTanks() {
public FluidTank[] getAllTanks() {
return new FluidTank[] { water, steam, carbonDioxide };
}

// do some opencomputer stuff
@Override
@Optional.Method(modid = "OpenComputers")
Expand All @@ -481,12 +481,12 @@ public Object[] getPressure(Context context, Arguments args) {
public Object[] getWater(Context context, Arguments args) {
return new Object[] {water.getFill()};
}

@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
public Object[] getSteam(Context context, Arguments args) {
return new Object[] {steam.getFill()};
}
}

@Callback(direct = true)
@Optional.Method(modid = "OpenComputers")
Expand All @@ -513,6 +513,17 @@ public Object[] setActive(Context context, Arguments args) {
return new Object[] {};
}

@Callback(direct = true)
Agarmal marked this conversation as resolved.
Show resolved Hide resolved
@Optional.Method(modid = "OpenComputers")
public Object[] ventCarbonDioxide(Context context, Arguments args) {
int ventAmount = args.optInteger(0, 1000); // Get how much CO2 to vent in mB (1000mB default)
Agarmal marked this conversation as resolved.
Show resolved Hide resolved
int fill = this.carbonDioxide.getFill();
this.carbonDioxide.setFill(fill - ventAmount);
Agarmal marked this conversation as resolved.
Show resolved Hide resolved
if(this.carbonDioxide.getFill() < 0)
this.carbonDioxide.setFill(0);
return new Object[] {};
}

@Override
@Optional.Method(modid = "OpenComputers")
public String[] methods() {
Expand All @@ -524,7 +535,8 @@ public String[] methods() {
"getCarbonDioxide",
"isActive",
"getInfo",
"setActive"
"setActive",
"ventCarbonDioxide"
};
}

Expand All @@ -548,6 +560,8 @@ public Object[] invoke(String method, Context context, Arguments args) throws Ex
return getInfo(context, args);
case ("setActive"):
return setActive(context, args);
case ("ventCarbonDioxide"):
return ventCarbonDioxide(context, args);
}
throw new NoSuchMethodException();
}
Expand Down