bit by bit we inch towards better fluid transfer

This commit is contained in:
Boblet 2022-11-14 16:33:19 +01:00
parent b4d8cd01c8
commit 55f20f7780
5 changed files with 155 additions and 3 deletions

View File

@ -0,0 +1,95 @@
package com.hbm.packet;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
public class BiomeSyncPacket implements IMessage {
int chunkX;
int chunkZ;
byte blockX;
byte blockZ;
byte biome;
byte[] biomeArray;
public BiomeSyncPacket() { }
public BiomeSyncPacket(int chunkX, int chunkZ, byte[] biomeArray) {
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.biomeArray = biomeArray;
}
public BiomeSyncPacket(int blockX, int blockZ, byte biome) {
this.chunkX = blockX << 4;
this.chunkZ = blockZ << 4;
this.blockX = (byte) (blockX & 15);
this.blockZ = (byte) (blockZ & 15);
this.biome = biome;
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.chunkX);
buf.writeInt(this.chunkZ);
if(this.biomeArray == null) {
buf.writeBoolean(false);
buf.writeByte(this.biome);
buf.writeByte(this.blockX);
buf.writeByte(this.blockZ);
} else {
buf.writeBoolean(true);
for(int i = 0; i < 256; i++) {
buf.writeByte(this.biomeArray[i]);
}
}
}
@Override
public void fromBytes(ByteBuf buf) {
this.chunkX = buf.readInt();
this.chunkZ = buf.readInt();
if(!buf.readBoolean()) {
this.biome = buf.readByte();
this.blockX = buf.readByte();
this.blockZ = buf.readByte();
} else {
buf.writeBoolean(true);
this.biomeArray = new byte[256];
for(int i = 0; i < 256; i++) {
this.biomeArray[i] = buf.readByte();
}
}
}
public static class Handler implements IMessageHandler<BiomeSyncPacket, IMessage> {
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(BiomeSyncPacket m, MessageContext ctx) {
World world = Minecraft.getMinecraft().theWorld;
if(!world.getChunkProvider().chunkExists(m.chunkX, m.chunkZ)) return null;
Chunk chunk = world.getChunkFromChunkCoords(m.chunkX, m.chunkZ);
if(m.biomeArray == null) {
chunk.getBiomeArray()[(m.blockZ & 15) << 4 | (m.blockX & 15)] = m.biome;
} else {
for(int i = 0; i < 256; i++) {
chunk.getBiomeArray()[i] = m.biomeArray[i];
}
}
return null;
}
}
}

View File

@ -103,6 +103,8 @@ public class PacketDispatcher {
wrapper.registerMessage(SyncButtonsPacket.Handler.class, SyncButtonsPacket.class, i++, Side.SERVER);
//General syncing for global values
wrapper.registerMessage(PermaSyncPacket.Handler.class, PermaSyncPacket.class, i++, Side.CLIENT);
//Syncs biome information for single positions or entire chunks
wrapper.registerMessage(BiomeSyncPacket.Handler.class, BiomeSyncPacket.class, i++, Side.CLIENT);
}
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import api.hbm.fluid.IFluidStandardReceiver;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.fluid.FluidType;
@ -24,8 +25,9 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.WeightedRandom;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntitySILEX extends TileEntityMachineBase implements IFluidAcceptor {
public class TileEntitySILEX extends TileEntityMachineBase implements IFluidAcceptor, IFluidStandardReceiver {
public EnumWavelengths mode = EnumWavelengths.NULL;
public boolean hasLaser;
@ -59,6 +61,10 @@ public class TileEntitySILEX extends TileEntityMachineBase implements IFluidAcce
tank.setType(1, 1, slots);
tank.loadTank(2, 3, slots);
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10).getRotation(ForgeDirection.UP);
this.trySubscribe(tank.getTankType(), worldObj, xCoord + dir.offsetX * 2, yCoord + 1, zCoord + dir.offsetZ * 2, dir);
this.trySubscribe(tank.getTankType(), worldObj, xCoord - dir.offsetX * 2, yCoord + 1, zCoord - dir.offsetZ * 2, dir.getOpposite());
loadFluid();
@ -324,4 +330,14 @@ public class TileEntitySILEX extends TileEntityMachineBase implements IFluidAcce
return 0;
}
@Override
public FluidTank[] getAllTanks() {
return new FluidTank[] {tank};
}
@Override
public FluidTank[] getReceivingTanks() {
return new FluidTank[] {tank};
}
}

View File

@ -224,8 +224,8 @@ public abstract class TileEntityRBMKBase extends TileEntity implements INBTPacke
protected void coolPassively() {
if(MainRegistry.proxy.getImpactFire(worldObj) > 1e-5) {
int light = this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, this.xCoord, this.yCoord, this.zCoord);
if(heat < 20 + (480 * (light / 15))) {
double light = this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, this.xCoord, this.yCoord, this.zCoord) / 15D;
if(heat < 20 + (480 * light)) {
this.heat += this.passiveCooling() * 2;
}
}

View File

@ -0,0 +1,39 @@
package com.hbm.world;
import com.hbm.packet.BiomeSyncPacket;
import com.hbm.packet.PacketDispatcher;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
public class WorldUtil {
public static void setBiome(World world, int x, int z, BiomeGenBase biome) {
Chunk chunk = world.getChunkFromBlockCoords(x, z);
chunk.getBiomeArray()[(z & 15) << 4 | (x & 15)] = (byte)(biome.biomeID & 255);
}
public static void syncBiomeChange(World world, Chunk chunk) {
/* "let's not make all this valuable information accessible, at all, hehe hoho huehue" -mojank, probably */
/*if(!(world instanceof WorldServer)) return;
WorldServer server = (WorldServer) world;
PlayerManager man = server.getPlayerManager();
Method getOrCreateChunkWatcher = ReflectionHelper.findMethod(PlayerManager.class, man, new String[] {"getOrCreateChunkWatcher"}, int.class, int.class, boolean.class);
int x = chunk.getChunkCoordIntPair().chunkXPos;
int z = chunk.getChunkCoordIntPair().chunkZPos;
PlayerManager.PlayerInstance playerinstance = (PlayerInstance) getOrCreateChunkWatcher.invoke(man, x, z, false);*/
/* this sucks ass */
ChunkCoordIntPair coord = chunk.getChunkCoordIntPair();
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(coord.chunkXPos, coord.chunkZPos, chunk.getBiomeArray()), new TargetPoint(world.provider.dimensionId, coord.getCenterXPos(), 128, coord.getCenterZPosition() /* who named you? */, 1024D));
}
public static void syncBiomeChange(World world, int x, int z) {
Chunk chunk = world.getChunkFromBlockCoords(x, z);
byte biome = chunk.getBiomeArray()[(z & 15) << 4 | (x & 15)];
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(x, z, chunk.getBiomeArray()), new TargetPoint(world.provider.dimensionId, x, 128, z, 1024D));
}
}