mirror of
https://github.com/LegacyModdingMC/ChunkAPI.git
synced 2026-10-26 14:24:51 +00:00
reformat code
This commit is contained in:
10 files changed
+115
-75
No files matched your search
@@ -46,8 +46,9 @@ public interface ChunkDataManager {
|
||||
*/
|
||||
interface PacketDataManager extends ChunkDataManager {
|
||||
/**
|
||||
* @implNote This is used to determine the size of the packet compression/decompression buffer.
|
||||
* @return The maximum amount of bytes your data can take up in a packet.
|
||||
*
|
||||
* @implNote This is used to determine the size of the packet compression/decompression buffer.
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
int maxPacketSize();
|
||||
@@ -118,6 +119,7 @@ public interface ChunkDataManager {
|
||||
default boolean sectionPrivilegedAccess() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes your data into an NBT tag. This is used when saving the chunk to disk.
|
||||
*/
|
||||
|
||||
@@ -18,22 +18,28 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class is used to register ChunkDataManagers.
|
||||
*
|
||||
* @see ChunkDataManager
|
||||
*/
|
||||
public class ChunkDataRegistry {
|
||||
/**
|
||||
* Registers a ChunkDataManager. Only do this during the preInit phase.
|
||||
*
|
||||
* @param manager The manager to register.
|
||||
* @throws IllegalStateException If the registration stage is over.
|
||||
*
|
||||
* @throws IllegalStateException If the registration stage is over.
|
||||
* @throws IllegalArgumentException If the manager has a duplicate id.
|
||||
*/
|
||||
public static void registerDataManager(ChunkDataManager manager) throws IllegalStateException, IllegalArgumentException {
|
||||
public static void registerDataManager(ChunkDataManager manager)
|
||||
throws IllegalStateException, IllegalArgumentException {
|
||||
ChunkDataRegistryImpl.registerDataManager(manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables a ChunkDataManager. Only do this during the preInit phase.
|
||||
*
|
||||
* @param id The id of the manager to disable.
|
||||
*
|
||||
* @throws IllegalStateException If the disable stage is over.
|
||||
*/
|
||||
public static void disableDataManager(String domain, String id) throws IllegalStateException {
|
||||
|
||||
@@ -19,7 +19,6 @@ import lombok.var;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
|
||||
@@ -39,7 +38,9 @@ public class ChunkDataRegistryImpl {
|
||||
private static final Map<String, ChunkDataManager.SectionNBTDataManager> sectionNBTManagers = new HashMap<>();
|
||||
private static final Set<String> disabledManagers = new HashSet<>();
|
||||
private static int maxPacketSize = 4;
|
||||
public static void registerDataManager(ChunkDataManager manager) throws IllegalStateException, IllegalArgumentException {
|
||||
|
||||
public static void registerDataManager(ChunkDataManager manager)
|
||||
throws IllegalStateException, IllegalArgumentException {
|
||||
if (Loader.instance().getLoaderState() != LoaderState.INITIALIZATION) {
|
||||
throw new IllegalStateException("ChunkDataManager registration is not allowed at this time! " +
|
||||
"Please register your ChunkDataManager in the init phase.");
|
||||
@@ -74,7 +75,8 @@ public class ChunkDataRegistryImpl {
|
||||
throw new IllegalStateException("ChunkDataManager disabling is not allowed at this time! " +
|
||||
"Please disable any ChunkDataManagers in the postInit phase.");
|
||||
}
|
||||
Common.LOG.warn("Disabling ChunkDataManager " + id + " in domain " + domain + ". See the stacktrace for the source of this event.", new Throwable());
|
||||
Common.LOG.warn("Disabling ChunkDataManager " + id + " in domain " + domain +
|
||||
". See the stacktrace for the source of this event.", new Throwable());
|
||||
val manager = domain + ":" + id;
|
||||
//Remove the manager from the list of managers, if it exists
|
||||
if (managers.remove(manager)) {
|
||||
@@ -133,7 +135,7 @@ public class ChunkDataRegistryImpl {
|
||||
val buf = ByteBuffer.wrap(data);
|
||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
buf.putInt(packetManagers.size());
|
||||
for (val pair: packetManagers.entrySet()) {
|
||||
for (val pair : packetManagers.entrySet()) {
|
||||
val id = pair.getKey();
|
||||
val manager = pair.getValue();
|
||||
writeString(buf, id);
|
||||
@@ -191,25 +193,27 @@ public class ChunkDataRegistryImpl {
|
||||
}
|
||||
|
||||
public static void writeSectionToNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound sectionNBT) {
|
||||
for (val manager: sectionNBTManagers.values()) {
|
||||
manager.writeSectionToNBT(chunk, ebs, createManagerNBT(manager.sectionPrivilegedAccess(), sectionNBT, manager));
|
||||
for (val manager : sectionNBTManagers.values()) {
|
||||
manager.writeSectionToNBT(chunk, ebs,
|
||||
createManagerNBT(manager.sectionPrivilegedAccess(), sectionNBT, manager));
|
||||
}
|
||||
}
|
||||
|
||||
public static void readSectionFromNBT(Chunk chunk, ExtendedBlockStorage ebs, NBTTagCompound sectionNBT) {
|
||||
for (val manager: sectionNBTManagers.values()) {
|
||||
manager.readSectionFromNBT(chunk, ebs, getManagerNBT(manager.sectionPrivilegedAccess(), sectionNBT, manager));
|
||||
for (val manager : sectionNBTManagers.values()) {
|
||||
manager.readSectionFromNBT(chunk, ebs,
|
||||
getManagerNBT(manager.sectionPrivilegedAccess(), sectionNBT, manager));
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeChunkToNBT(Chunk chunk, NBTTagCompound chunkNBT) {
|
||||
for (val manager: chunkNBTManagers.values()) {
|
||||
for (val manager : chunkNBTManagers.values()) {
|
||||
manager.writeChunkToNBT(chunk, createManagerNBT(manager.chunkPrivilegedAccess(), chunkNBT, manager));
|
||||
}
|
||||
}
|
||||
|
||||
public static void readChunkFromNBT(Chunk chunk, NBTTagCompound chunkNBT) {
|
||||
for (val manager: chunkNBTManagers.values()) {
|
||||
for (val manager : chunkNBTManagers.values()) {
|
||||
manager.readChunkFromNBT(chunk, getManagerNBT(manager.chunkPrivilegedAccess(), chunkNBT, manager));
|
||||
}
|
||||
}
|
||||
|
||||
+19
-14
@@ -29,23 +29,28 @@ import java.util.Map;
|
||||
|
||||
@Mixin(Chunk.class)
|
||||
public abstract class ChunkMixin {
|
||||
@Shadow public Map<?, ?> chunkTileEntityMap;
|
||||
@Shadow
|
||||
public Map<?, ?> chunkTileEntityMap;
|
||||
@Shadow
|
||||
public boolean isLightPopulated;
|
||||
@Shadow
|
||||
public boolean isTerrainPopulated;
|
||||
@Shadow
|
||||
public World worldObj;
|
||||
@Shadow
|
||||
private ExtendedBlockStorage[] storageArrays;
|
||||
|
||||
@Shadow private ExtendedBlockStorage[] storageArrays;
|
||||
@Shadow
|
||||
public abstract void generateHeightMap();
|
||||
|
||||
@Shadow public boolean isLightPopulated;
|
||||
@Shadow
|
||||
public abstract Block getBlock(int p_150810_1_, int p_150810_2_, int p_150810_3_);
|
||||
|
||||
@Shadow public boolean isTerrainPopulated;
|
||||
@Shadow
|
||||
public abstract int getBlockMetadata(int p_76628_1_, int p_76628_2_, int p_76628_3_);
|
||||
|
||||
@Shadow public abstract void generateHeightMap();
|
||||
|
||||
@Shadow public abstract Block getBlock(int p_150810_1_, int p_150810_2_, int p_150810_3_);
|
||||
|
||||
@Shadow public abstract int getBlockMetadata(int p_76628_1_, int p_76628_2_, int p_76628_3_);
|
||||
|
||||
@Shadow public World worldObj;
|
||||
|
||||
@Shadow public abstract ExtendedBlockStorage[] getBlockStorageArray();
|
||||
@Shadow
|
||||
public abstract ExtendedBlockStorage[] getBlockStorageArray();
|
||||
|
||||
/**
|
||||
* @author FalsePattern
|
||||
@@ -72,7 +77,7 @@ public abstract class ChunkMixin {
|
||||
}
|
||||
}
|
||||
|
||||
ChunkDataRegistryImpl.readFromBuffer((Chunk)(Object)this, ebsMask, forceUpdate, data);
|
||||
ChunkDataRegistryImpl.readFromBuffer((Chunk) (Object) this, ebsMask, forceUpdate, data);
|
||||
|
||||
for (int i = 0; i < storageArrays.length; ++i) {
|
||||
if ((storageArrays[i] != null) && ((ebsMask & (1 << i)) != 0)) {
|
||||
|
||||
+7
-5
@@ -37,12 +37,13 @@ public abstract class AnvilChunkLoaderMixin {
|
||||
/**
|
||||
* Writes the Chunk passed as an argument to the NBTTagCompound also passed, using the World argument to retrieve
|
||||
* the Chunk's last update time.
|
||||
*
|
||||
* @author FalsePattern
|
||||
* @reason Replace functionality
|
||||
*/
|
||||
@Overwrite
|
||||
private void writeChunkToNBT(Chunk chunk, World world, NBTTagCompound nbt) {
|
||||
nbt.setByte("V", (byte)1);
|
||||
nbt.setByte("V", (byte) 1);
|
||||
nbt.setInteger("xPos", chunk.xPosition);
|
||||
nbt.setInteger("zPos", chunk.zPosition);
|
||||
System.out.println("Saving chunk " + chunk.xPosition + ", " + chunk.zPosition);
|
||||
@@ -59,6 +60,7 @@ public abstract class AnvilChunkLoaderMixin {
|
||||
/**
|
||||
* Reads the data stored in the given NBTTagCompound and creates a Chunk with that data in the given World.
|
||||
* Returns the created Chunk.
|
||||
*
|
||||
* @author FalsePattern
|
||||
* @reason Replace functionality
|
||||
*/
|
||||
@@ -66,7 +68,7 @@ public abstract class AnvilChunkLoaderMixin {
|
||||
private Chunk readChunkFromNBT(World world, NBTTagCompound nbt) {
|
||||
int x = nbt.getInteger("xPos");
|
||||
int z = nbt.getInteger("zPos");
|
||||
System.out.println("Loading chunk " + x + ", " + z );
|
||||
System.out.println("Loading chunk " + x + ", " + z);
|
||||
Chunk chunk = new Chunk(world, x, z);
|
||||
chunk.heightMap = nbt.getIntArray("HeightMap");
|
||||
chunk.isTerrainPopulated = nbt.getBoolean("TerrainPopulated");
|
||||
@@ -110,7 +112,7 @@ public abstract class AnvilChunkLoaderMixin {
|
||||
NBTTagList sections = new NBTTagList();
|
||||
NBTTagCompound section;
|
||||
|
||||
for (ExtendedBlockStorage ebs: ebsList) {
|
||||
for (ExtendedBlockStorage ebs : ebsList) {
|
||||
if (ebs != null) {
|
||||
section = new NBTTagCompound();
|
||||
section.setByte("Y", (byte) (ebs.getYLocation() >> 4 & 255));
|
||||
@@ -127,7 +129,7 @@ public abstract class AnvilChunkLoaderMixin {
|
||||
NBTTagList entities = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < chunk.entityLists.length; ++i) {
|
||||
for (Object o: chunk.entityLists[i]) {
|
||||
for (Object o : chunk.entityLists[i]) {
|
||||
Entity entity = (Entity) o;
|
||||
val entityNBT = new NBTTagCompound();
|
||||
|
||||
@@ -147,7 +149,7 @@ public abstract class AnvilChunkLoaderMixin {
|
||||
nbt.setTag("Entities", entities);
|
||||
NBTTagList tileEntities = new NBTTagList();
|
||||
|
||||
for (Object o: chunk.chunkTileEntityMap.values()) {
|
||||
for (Object o : chunk.chunkTileEntityMap.values()) {
|
||||
TileEntity tileentity = (TileEntity) o;
|
||||
val tileEntityNBT = new NBTTagCompound();
|
||||
try {
|
||||
|
||||
+22
-13
@@ -33,18 +33,24 @@ import java.util.zip.Inflater;
|
||||
@Mixin(S21PacketChunkData.class)
|
||||
public abstract class S21PacketChunkDataMixin {
|
||||
|
||||
@Shadow private Semaphore deflateGate;
|
||||
@Shadow(aliases = "field_149284_a") private int xPosition;
|
||||
@Shadow(aliases = "field_149282_b") private int zPosition;
|
||||
@Shadow(aliases = "field_149283_c") private int ebsMask;
|
||||
@Shadow(aliases = "field_149281_e") private byte[] deflatedData;
|
||||
@Shadow(aliases = "field_149278_f") private byte[] data;
|
||||
@Shadow(aliases = "field_149279_g") private boolean forceUpdate;
|
||||
@Shadow(aliases = "field_149285_h") private int deflatedSize;
|
||||
@Shadow(aliases = "field_149286_i") private static byte[] buffer;
|
||||
|
||||
@Shadow protected abstract void deflate();
|
||||
|
||||
@Shadow(aliases = "field_149286_i")
|
||||
private static byte[] buffer;
|
||||
@Shadow
|
||||
private Semaphore deflateGate;
|
||||
@Shadow(aliases = "field_149284_a")
|
||||
private int xPosition;
|
||||
@Shadow(aliases = "field_149282_b")
|
||||
private int zPosition;
|
||||
@Shadow(aliases = "field_149283_c")
|
||||
private int ebsMask;
|
||||
@Shadow(aliases = "field_149281_e")
|
||||
private byte[] deflatedData;
|
||||
@Shadow(aliases = "field_149278_f")
|
||||
private byte[] data;
|
||||
@Shadow(aliases = "field_149279_g")
|
||||
private boolean forceUpdate;
|
||||
@Shadow(aliases = "field_149285_h")
|
||||
private int deflatedSize;
|
||||
|
||||
@ModifyConstant(method = {"<clinit>", "func_149275_c"},
|
||||
constant = @Constant(intValue = 196864),
|
||||
@@ -83,6 +89,9 @@ public abstract class S21PacketChunkDataMixin {
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Shadow
|
||||
protected abstract void deflate();
|
||||
|
||||
/**
|
||||
* @author FalsePattern
|
||||
* @reason Replace functionality
|
||||
@@ -103,7 +112,7 @@ public abstract class S21PacketChunkDataMixin {
|
||||
data.writeInt(zPosition);
|
||||
System.out.println("Writing chunk packet (" + xPosition + ", " + zPosition + ")");
|
||||
data.writeBoolean(forceUpdate);
|
||||
data.writeShort((short)(ebsMask & 0xFFFF));
|
||||
data.writeShort((short) (ebsMask & 0xFFFF));
|
||||
data.writeInt(this.data.length);
|
||||
data.writeInt(deflatedSize);
|
||||
data.writeBytes(deflatedData, 0, deflatedSize);
|
||||
|
||||
+22
-14
@@ -28,19 +28,27 @@ import java.util.zip.Inflater;
|
||||
|
||||
@Mixin(S26PacketMapChunkBulk.class)
|
||||
public abstract class S26PacketMapChunkBulkMixin {
|
||||
@Shadow(aliases = "field_149263_e") private byte[] deflatedData;
|
||||
@Shadow(aliases = "field_149268_i")
|
||||
private static byte[] inflaterBuffer;
|
||||
@Shadow(aliases = "field_149263_e")
|
||||
private byte[] deflatedData;
|
||||
@Shadow
|
||||
private Semaphore deflateGate;
|
||||
@Shadow(aliases = "field_149266_a")
|
||||
private int[] xPositions;
|
||||
@Shadow(aliases = "field_149264_b")
|
||||
private int[] zPositions;
|
||||
@Shadow(aliases = "field_149265_c")
|
||||
private int[] ebsMasks;
|
||||
@Shadow(aliases = "field_149261_g")
|
||||
private int deflatedSize;
|
||||
@Shadow(aliases = "field_149267_h")
|
||||
private boolean skylight;
|
||||
@Shadow(aliases = "field_149260_f")
|
||||
private byte[][] datas;
|
||||
|
||||
@Shadow private Semaphore deflateGate;
|
||||
|
||||
@Shadow protected abstract void deflate();
|
||||
|
||||
@Shadow(aliases = "field_149266_a") private int[] xPositions;
|
||||
@Shadow(aliases = "field_149264_b") private int[] zPositions;
|
||||
@Shadow(aliases = "field_149265_c") private int[] ebsMasks;
|
||||
@Shadow(aliases = "field_149261_g") private int deflatedSize;
|
||||
@Shadow(aliases = "field_149267_h") private boolean skylight;
|
||||
@Shadow(aliases = "field_149260_f") private byte[][] datas;
|
||||
@Shadow(aliases = "field_149268_i") private static byte[] inflaterBuffer;
|
||||
@Shadow
|
||||
protected abstract void deflate();
|
||||
|
||||
/**
|
||||
* @author FalsePattern
|
||||
@@ -106,7 +114,7 @@ public abstract class S26PacketMapChunkBulkMixin {
|
||||
}
|
||||
|
||||
data.writeShort(xPositions.length);
|
||||
for (byte[] bytes: datas) {
|
||||
for (byte[] bytes : datas) {
|
||||
data.writeInt(bytes.length);
|
||||
}
|
||||
data.writeInt(deflatedSize);
|
||||
@@ -116,7 +124,7 @@ public abstract class S26PacketMapChunkBulkMixin {
|
||||
for (int i = 0; i < xPositions.length; ++i) {
|
||||
data.writeInt(xPositions[i]);
|
||||
data.writeInt(zPositions[i]);
|
||||
data.writeShort((short)(ebsMasks[i] & 65535));
|
||||
data.writeShort((short) (ebsMasks[i] & 65535));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,8 @@ import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class BiomeManager extends VanillaManager implements ChunkDataManager.PacketDataManager, ChunkDataManager.ChunkNBTDataManager {
|
||||
public class BiomeManager extends VanillaManager
|
||||
implements ChunkDataManager.PacketDataManager, ChunkDataManager.ChunkNBTDataManager {
|
||||
public static final int BYTES_PER_CHUNK = 256;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,8 @@ import java.nio.ByteBuffer;
|
||||
import static com.falsepattern.chunk.internal.Common.BLOCKS_PER_EBS;
|
||||
import static com.falsepattern.chunk.internal.Common.EBS_PER_CHUNK;
|
||||
|
||||
public class BlockIDManager extends VanillaManager implements ChunkDataManager.PacketDataManager, ChunkDataManager.SectionNBTDataManager {
|
||||
public class BlockIDManager extends VanillaManager
|
||||
implements ChunkDataManager.PacketDataManager, ChunkDataManager.SectionNBTDataManager {
|
||||
private static final int LSB_BYTES_PER_EBS = BLOCKS_PER_EBS;
|
||||
private static final int MSB_BYTES_PER_EBS = BLOCKS_PER_EBS / 2;
|
||||
private static final int HEADER_SIZE = 2;
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
[
|
||||
{
|
||||
"modid": "${modId}",
|
||||
"name": "${modName}",
|
||||
"description": "A chunk data hooking library.",
|
||||
"version": "${modVersion}",
|
||||
"mcversion": "${minecraftVersion}",
|
||||
"url": "https://github.com/FalsePattern/ChunkAPI",
|
||||
"updateUrl": "",
|
||||
"authorList": ["FalsePattern"],
|
||||
"credits": "",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
"dependencies": []
|
||||
}
|
||||
{
|
||||
"modid": "${modId}",
|
||||
"name": "${modName}",
|
||||
"description": "Chunk data, simplified.",
|
||||
"version": "${modVersion}",
|
||||
"mcversion": "${minecraftVersion}",
|
||||
"url": "https://github.com/FalsePattern/ChunkAPI",
|
||||
"updateUrl": "",
|
||||
"authorList": [
|
||||
"FalsePattern"
|
||||
],
|
||||
"credits": "",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
"dependencies": []
|
||||
}
|
||||
]
|
||||
Reference in new issue
Block a user