EndlessIDs compat

This commit is contained in:
George Paton 2024-09-26 12:27:07 +10:00
parent 2edc4304b5
commit 70be7c4cf5
4 changed files with 89 additions and 22 deletions

View File

@ -75,6 +75,14 @@ repositories {
name = "gt"
url = "https://gregtech.mechaenetia.com/"
}
maven {
name = 'FalsePattern'
url = "https://mvn.falsepattern.com/releases/"
}
maven {
name = "GitHub"
url = "https://jitpack.io"
}
//maven {
// name = "CurseForge"
// url = "https://minecraft.curseforge.com/api/maven/"
@ -94,6 +102,8 @@ dependencies {
compileOnly "inventorytweaks:InventoryTweaks:1.59-dev:deobf"
implementation "li.cil.oc:OpenComputers:MC1.7.10-1.5.+:api"
compileOnly 'com.falsepattern:endlessids-mc1.7.10:1.5.4:dev'
}
processResources {

View File

@ -1,5 +1,9 @@
package com.hbm.packet.toclient;
import cpw.mods.fml.common.Loader;
import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook;
import com.hbm.util.Compat;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@ -16,18 +20,26 @@ public class BiomeSyncPacket implements IMessage {
int chunkZ;
byte blockX;
byte blockZ;
byte biome;
byte[] biomeArray;
short biome;
short[] biomeArray;
public BiomeSyncPacket() { }
public BiomeSyncPacket(int chunkX, int chunkZ, byte[] biomeArray) {
this(chunkX, chunkZ, bytesToShorts(biomeArray));
}
public BiomeSyncPacket(int blockX, int blockZ, byte biome) {
this(blockX, blockZ, (short) biome);
}
public BiomeSyncPacket(int chunkX, int chunkZ, short[] biomeArray) {
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.biomeArray = biomeArray;
}
public BiomeSyncPacket(int blockX, int blockZ, byte biome) {
public BiomeSyncPacket(int blockX, int blockZ, short biome) {
this.chunkX = blockX >> 4;
this.chunkZ = blockZ >> 4;
this.blockX = (byte) (blockX & 15);
@ -42,13 +54,13 @@ public class BiomeSyncPacket implements IMessage {
if(this.biomeArray == null) {
buf.writeBoolean(false);
buf.writeByte(this.biome);
buf.writeShort(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]);
buf.writeShort(this.biomeArray[i]);
}
}
}
@ -59,17 +71,27 @@ public class BiomeSyncPacket implements IMessage {
this.chunkZ = buf.readInt();
if(!buf.readBoolean()) {
this.biome = buf.readByte();
this.biome = buf.readShort();
this.blockX = buf.readByte();
this.blockZ = buf.readByte();
} else {
this.biomeArray = new byte[256];
this.biomeArray = new short[256];
for(int i = 0; i < 256; i++) {
this.biomeArray[i] = buf.readByte();
this.biomeArray[i] = buf.readShort();
}
}
}
private final static short[] bytesToShorts(byte[] byteArray) {
int size = byteArray.length;
short[] shortArray = new short[size];
for(int index = 0; index < size; index++)
shortArray[index] = (short) byteArray[index];
return shortArray;
}
public static class Handler implements IMessageHandler<BiomeSyncPacket, IMessage> {
@Override
@ -80,14 +102,28 @@ public class BiomeSyncPacket implements IMessage {
if(!world.getChunkProvider().chunkExists(m.chunkX, m.chunkZ)) return null;
Chunk chunk = world.getChunkFromChunkCoords(m.chunkX, m.chunkZ);
chunk.isModified = true;
if(m.biomeArray == null) {
chunk.getBiomeArray()[(m.blockZ & 15) << 4 | (m.blockX & 15)] = m.biome;
world.markBlockRangeForRenderUpdate(m.chunkX << 4, 0, m.chunkZ << 4, m.chunkX << 4, 255, m.chunkZ << 4);
if(Loader.isModLoaded(Compat.MOD_EIDS)) {
if (m.biomeArray == null) {
ChunkBiomeHook hook = (ChunkBiomeHook) chunk;
hook.getBiomeShortArray()[(m.blockZ & 15) << 4 | m.blockX & 15] = m.biome;
world.markBlockRangeForRenderUpdate(m.chunkX << 4, 0, m.chunkZ << 4, m.chunkX << 4, 255, m.chunkZ << 4);
} else {
for (int i = 0; i < 255; ++i) {
ChunkBiomeHook hook = (ChunkBiomeHook) chunk;
hook.getBiomeShortArray()[i] = m.biomeArray[i];
world.markBlockRangeForRenderUpdate(m.chunkX << 4, 0, m.chunkZ << 4, (m.chunkX << 4) + 15, 255, (m.chunkZ << 4) + 15);
}
}
} else {
for(int i = 0; i < 256; i++) {
chunk.getBiomeArray()[i] = m.biomeArray[i];
world.markBlockRangeForRenderUpdate(m.chunkX << 4, 0, m.chunkZ << 4, (m.chunkX << 4) + 15, 255, (m.chunkZ << 4) + 15);
if(m.biomeArray == null) {
chunk.getBiomeArray()[(m.blockZ & 15) << 4 | (m.blockX & 15)] = (byte) m.biome;
world.markBlockRangeForRenderUpdate(m.chunkX << 4, 0, m.chunkZ << 4, m.chunkX << 4, 255, m.chunkZ << 4);
} else {
for(int i = 0; i < 256; i++) {
chunk.getBiomeArray()[i] = (byte) m.biomeArray[i];
world.markBlockRangeForRenderUpdate(m.chunkX << 4, 0, m.chunkZ << 4, (m.chunkX << 4) + 15, 255, (m.chunkZ << 4) + 15);
}
}
}

View File

@ -35,6 +35,7 @@ public class Compat {
public static final String MOD_TIC = "TConstruct";
public static final String MOD_RC = "Railcraft";
public static final String MOD_TC = "tc";
public static final String MOD_EIDS = "endlessids";
public static Item tryLoadItem(String domain, String name) {
return (Item) Item.itemRegistry.getObject(getReg(domain, name));

View File

@ -2,7 +2,9 @@ package com.hbm.world;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.toclient.BiomeSyncPacket;
import com.hbm.util.Compat;
import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
@ -21,19 +23,33 @@ 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);
if(Loader.isModLoaded(Compat.MOD_EIDS)) {
short[] array = ((ChunkBiomeHook) chunk).getBiomeShortArray();
array[(z & 15) << 4 | x & 15] = (short) biome.biomeID;
} else {
chunk.getBiomeArray()[(z & 15) << 4 | (x & 15)] = (byte)(biome.biomeID & 255);
}
chunk.isModified = true;
}
public static void syncBiomeChange(World world, int x, int z) {
Chunk chunk = world.getChunkFromBlockCoords(x, z);
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(x >> 4, z >> 4, chunk.getBiomeArray()), new TargetPoint(world.provider.dimensionId, x, 128, z, 1024D));
if(Loader.isModLoaded(Compat.MOD_EIDS)) {
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(x >> 4, z >> 4, ((ChunkBiomeHook) chunk).getBiomeShortArray()), new TargetPoint(world.provider.dimensionId, x, 128, z, 1024D));
} else {
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(x >> 4, z >> 4, chunk.getBiomeArray()), new TargetPoint(world.provider.dimensionId, x, 128, z, 1024D));
}
}
public static void syncBiomeChangeBlock(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, biome), new TargetPoint(world.provider.dimensionId, x, 128, z, 1024D));
if(Loader.isModLoaded(Compat.MOD_EIDS)) {
short biome = ((ChunkBiomeHook) chunk).getBiomeShortArray()[(z & 15) << 4 | (x & 15)];
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(x, z, biome), new TargetPoint(world.provider.dimensionId, x, 128, z, 1024D));
} else {
byte biome = chunk.getBiomeArray()[(z & 15) << 4 | (x & 15)];
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(x, z, biome), new TargetPoint(world.provider.dimensionId, x, 128, z, 1024D));
}
}
public static void syncBiomeChange(World world, Chunk chunk) {
@ -48,7 +64,11 @@ public class WorldUtil {
/* 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));
if(Loader.isModLoaded(Compat.MOD_EIDS)) {
PacketDispatcher.wrapper.sendToAllAround(new BiomeSyncPacket(coord.chunkXPos, coord.chunkZPos, ((ChunkBiomeHook) chunk).getBiomeShortArray()), new TargetPoint(world.provider.dimensionId, coord.getCenterXPos(), 128, coord.getCenterZPosition() /* who named you? */, 1024D));
} else {
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));
}
}
/**Chunkloads the chunk the entity is going to spawn in and then spawns it