-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Обновлён Nukkit-Mot - Добавлена регестрация биомоы работает
- Loading branch information
Showing
8 changed files
with
181 additions
and
15 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.reider745.hooks; | ||
|
||
import cn.nukkit.block.Block; | ||
import cn.nukkit.level.biome.Biome; | ||
import cn.nukkit.network.protocol.BiomeDefinitionListPacket; | ||
import com.reider745.api.ReflectHelper; | ||
import com.reider745.api.hooks.HookClass; | ||
import com.reider745.api.hooks.TypeHook; | ||
import com.reider745.api.hooks.annotation.Hooks; | ||
import com.reider745.api.hooks.annotation.Inject; | ||
import com.reider745.world.BiomesMethods; | ||
import javassist.CtClass; | ||
import javassist.CtField; | ||
import javassist.Modifier; | ||
|
||
@Hooks(className = "cn.nukkit.level.biome.Biome") | ||
public class BiomesHooks implements HookClass { | ||
private static final int MAX_ID = 512; | ||
|
||
@Override | ||
public void rebuildField(CtClass ctClass, CtField field) { | ||
String name = field.getName(); | ||
if (name.equals("biomes")) { | ||
field.setModifiers(Modifier.PUBLIC | Modifier.STATIC); | ||
|
||
} | ||
} | ||
|
||
public static void init() { | ||
ReflectHelper.setField(Biome.class, "biomes", new Biome[MAX_ID]); | ||
} | ||
|
||
@Inject(className = "cn.nukkit.network.protocol.BiomeDefinitionListPacket", type = TypeHook.BEFORE_REPLACE) | ||
public static void encode(BiomeDefinitionListPacket self){ | ||
BiomesMethods.encode(self); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.reider745.world; | ||
|
||
import cn.nukkit.level.biome.Biome; | ||
import cn.nukkit.nbt.NBTIO; | ||
import cn.nukkit.nbt.tag.CompoundTag; | ||
import cn.nukkit.network.protocol.BiomeDefinitionListPacket; | ||
import com.reider745.api.ReflectHelper; | ||
import com.reider745.api.pointers.PointersStorage; | ||
import com.reider745.api.pointers.pointer_gen.PointerGenFastest; | ||
import com.zhekasmirnov.innercore.api.nbt.NativeCompoundTag; | ||
import org.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteOrder; | ||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
||
/* | ||
format BiomeDefinitionListPacket | ||
name: { | ||
temperature | ||
downfall | ||
} | ||
*/ | ||
public class BiomesMethods { | ||
private static class NukkitCustomBiome extends Biome { | ||
private final String name; | ||
|
||
public NukkitCustomBiome(String name){ | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
protected void reg(int id){ | ||
register(id, this); | ||
} | ||
} | ||
|
||
private static final PointersStorage<NukkitCustomBiome> customBiomesPointers = new PointersStorage<>("biomes", new PointerGenFastest(), false); | ||
private static final HashMap<Integer, NukkitCustomBiome> customBiomes = new HashMap<>(); | ||
private static final CompoundTag TAG_419; | ||
private static byte[] sendBiomes; | ||
|
||
static { | ||
try { | ||
TAG_419 = NBTIO.read((byte[]) Objects.requireNonNull(ReflectHelper.getField(BiomeDefinitionListPacket.class, "TAG_419")), ByteOrder.LITTLE_ENDIAN, true); | ||
sendBiomes = NBTIO.write(TAG_419, ByteOrder.LITTLE_ENDIAN, true); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static int pre_id = 256; | ||
|
||
public static long nativeRegister(String name) { | ||
NukkitCustomBiome biome = new NukkitCustomBiome(name); | ||
biome.reg(pre_id++); | ||
customBiomes.put(biome.getId(), biome); | ||
try{ | ||
final CompoundTag tag = new CompoundTag(); | ||
tag.putFloat("ash", .0f); | ||
tag.putFloat("blue_spores", .0f); | ||
tag.putFloat("red_spores", .0f); | ||
tag.putFloat("temperature", .5f); | ||
tag.putFloat("downfall", .5f); | ||
tag.putFloat("white_ash", .0f); | ||
|
||
final CompoundTag climate = new CompoundTag(); | ||
climate.putFloat("ash", .0f); | ||
climate.putFloat("downfall", .5f); | ||
climate.putFloat("red_spores", .0f); | ||
climate.putFloat("temperature", .5f); | ||
climate.putFloat("blue_spores", .0f); | ||
climate.putFloat("white_ash", .0f); | ||
tag.put("minecraft:climate", climate); | ||
|
||
TAG_419.put(name, tag); | ||
sendBiomes = NBTIO.write(TAG_419, ByteOrder.LITTLE_ENDIAN, true); | ||
}catch (Exception e){ | ||
throw new RuntimeException(e); | ||
} | ||
return customBiomesPointers.addPointer(biome); | ||
} | ||
|
||
public static int nativeGetId(long pointer) { | ||
return customBiomesPointers.get(pointer).getId(); | ||
} | ||
|
||
public static void encode(BiomeDefinitionListPacket self) { | ||
self.reset(); | ||
self.put(sendBiomes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters