Skip to content

Commit

Permalink
Fill int biome array after calling chunk generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Runemoro committed Jun 14, 2018
1 parent da86981 commit e384b99
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 91 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/dimdev/jeid/JEID.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@
import net.minecraft.item.ItemBlock;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeVoid;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.registries.IForgeRegistry;

import java.io.File;

@Mod(modid = "jeid",
name = "JustEnoughIDs",
updateJSON = "https://gist.githubusercontent.com/Runemoro/67b1d8d31af58e9d35410ef60b2017c3/raw/1fe08a6c45a1f481a8a2a8c71e52d4245dcb7713/jeid_update.json")
public class JEID {
private static final boolean DEBUG_BLOCK_IDS = false;
private static final boolean DEBUG_ITEM_IDS = false;
private static final boolean DEBUG_BIOME_IDS = true;
private static final boolean DEBUG_BIOME_IDS = false;
public static final Biome errorBiome = new BiomeVoid(new Biome.BiomeProperties("A mod doesn't support extended biome IDs -- report to JEID"))
.setRegistryName("jeid:error_biome");

@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
File modDir = new File(event.getModConfigurationDirectory(), "jeid");
modDir.mkdirs();

if (DEBUG_BLOCK_IDS) {
IForgeRegistry<Block> blockRegistry = GameRegistry.findRegistry(Block.class);
IForgeRegistry<Item> itemRegistry = GameRegistry.findRegistry(Item.class);
Expand Down Expand Up @@ -62,5 +60,7 @@ public void onPreInit(FMLPreInitializationEvent event) {
biomeRegistry.register(biome);
}
}

GameRegistry.findRegistry(Biome.class).register(errorBiome);
}
}
12 changes: 7 additions & 5 deletions src/main/java/org/dimdev/jeid/mixin/core/MixinChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import net.minecraft.world.biome.BiomeProvider;
import net.minecraft.world.chunk.Chunk;
import org.dimdev.jeid.INewChunk;
import org.dimdev.jeid.JEID;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Arrays;

@Mixin(Chunk.class)
public class MixinChunk implements INewChunk {
private static final byte errorBiomeID = (byte) Biome.REGISTRY.getIDForObject(JEID.errorBiome);
private final int[] intBiomeArray = generateIntBiomeArray();

private static int[] generateIntBiomeArray() {
Expand All @@ -37,9 +37,11 @@ public void setIntBiomeArray(int[] intBiomeArray) {
System.arraycopy(intBiomeArray, 0, this.intBiomeArray, 0, this.intBiomeArray.length);
}

@Inject(method = "getBiomeArray", at = @At("HEAD"))
public void onGetBiomeArray(CallbackInfoReturnable<byte[]> cir) {
throw new RuntimeException("A mod needs support for extended biome IDs, report to JustEnoughIDs.");
@Overwrite
public byte[] getBiomeArray() {
byte[] arr = new byte[256];
Arrays.fill(arr, errorBiomeID);
return arr;
}

@Redirect(method = "read", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketBuffer;readBytes([B)Lio/netty/buffer/ByteBuf;", ordinal = 2))
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/org/dimdev/jeid/mixin/core/MixinChunkGenerator.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.dimdev.jeid.mixin.core;

import net.minecraft.world.WorldServer;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.gen.IChunkGenerator;
import org.dimdev.jeid.INewChunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ChunkProviderServer.class)
public class MixinChunkProviderServer {
@Shadow @Final public WorldServer world;
private Biome[] reusableBiomeList = new Biome[256];

/** @reason Return an empty biome byte array if the chunk is using an int biome array. **/
@Redirect(method = "provideChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/IChunkGenerator;generateChunk(II)Lnet/minecraft/world/chunk/Chunk;"))
private Chunk generateChunk(IChunkGenerator generator, int x, int z) {
Chunk chunk = generator.generateChunk(x, z);
Biome[] biomes = world.getBiomeProvider().getBiomes(reusableBiomeList, x * 16, z * 16, 16, 16);

INewChunk newChunk = (INewChunk) chunk;
int[] intBiomeArray = newChunk.getIntBiomeArray();
for (int i = 0; i < intBiomeArray.length; ++i) {
intBiomeArray[i] = Biome.getIdForBiome(biomes[i]);
}
return chunk;
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/mixins.jeid.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"MixinAnvilChunkLoader",
"MixinBlock",
"MixinChunk",
"MixinChunkGenerator",
"MixinSPacketChunkData",
"MixinGenLayerVoronoiZoom",
"MixinChunkPrimer"
"MixinChunkPrimer",
"MixinChunkProviderServer"
],
"client": [],
"injectors": {
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/mixins.jeid.modsupport.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"mixins": [],
"client": [
"MixinModBiomes",
"MixinModChunkGenerator",
"MixinBOPCommand"
],
"injectors": {
Expand Down

0 comments on commit e384b99

Please sign in to comment.