|
| 1 | +package org.dimdev.jeid.mixin.modsupport.biometweaker; |
| 2 | + |
| 3 | +import me.superckl.biometweaker.server.command.CommandSetBiome; |
| 4 | +import net.minecraft.command.ICommandSender; |
| 5 | +import net.minecraft.server.MinecraftServer; |
| 6 | +import net.minecraft.util.math.BlockPos; |
| 7 | +import net.minecraft.util.math.ChunkPos; |
| 8 | +import net.minecraft.util.text.Style; |
| 9 | +import net.minecraft.util.text.TextComponentTranslation; |
| 10 | +import net.minecraft.util.text.TextFormatting; |
| 11 | +import net.minecraft.world.World; |
| 12 | +import net.minecraft.world.biome.Biome; |
| 13 | +import net.minecraft.world.chunk.Chunk; |
| 14 | +import net.minecraftforge.fml.common.network.NetworkRegistry; |
| 15 | +import org.dimdev.jeid.INewChunk; |
| 16 | +import org.dimdev.jeid.Utils; |
| 17 | +import org.dimdev.jeid.network.BiomeArrayMessage; |
| 18 | +import org.dimdev.jeid.network.BiomeChangeMessage; |
| 19 | +import org.dimdev.jeid.network.MessageManager; |
| 20 | +import org.spongepowered.asm.mixin.Mixin; |
| 21 | +import org.spongepowered.asm.mixin.injection.At; |
| 22 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 23 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 24 | +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; |
| 25 | + |
| 26 | +import java.util.Arrays; |
| 27 | + |
| 28 | +@Mixin(CommandSetBiome.class) |
| 29 | +public class MixinCommandSetBiome { |
| 30 | + @Inject(method = "func_184881_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;func_76605_m()[B", remap = false), locals = LocalCapture.CAPTURE_FAILHARD, remap = false) |
| 31 | + private void setBiomeArrayElement(MinecraftServer server, ICommandSender sender, String args[], CallbackInfo ci, BlockPos coord, World world, Biome gen, Integer i, int id, boolean blocks, int count, int x, int z, int realX, int realZ, Chunk chunk) { |
| 32 | + Utils.LOGGER.info("setting biome at {}, {}", x, z); |
| 33 | + ((INewChunk) chunk).getIntBiomeArray()[(z & 0xF) << 4 | x & 0xF] = id; |
| 34 | + MessageManager.CHANNEL.sendToAllTracking(new BiomeChangeMessage(x, z, id), new NetworkRegistry.TargetPoint(world.provider.getDimension(), coord.getX(), coord.getY(), coord.getZ(), 256)); |
| 35 | + } |
| 36 | + |
| 37 | + @Inject(method = "func_184881_a", at = @At(value = "INVOKE", target = "Ljava/util/Arrays;fill([BB)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, remap = false) |
| 38 | + private void setBiomeArray(MinecraftServer server, ICommandSender sender, String args[], CallbackInfo ci, BlockPos coord, World world, Biome gen, Integer i, int id, boolean blocks, int count, byte biomeArray[]) { |
| 39 | + final int[] intBiomeArray = new int[256]; |
| 40 | + Arrays.fill(intBiomeArray, id); |
| 41 | + ChunkPos chunkPos = new ChunkPos(coord); |
| 42 | + |
| 43 | + for (int x = chunkPos.x - i; x <= chunkPos.x + i; x++) { |
| 44 | + for (int z = chunkPos.z - i; z <= chunkPos.z + i; z++) { |
| 45 | + ((INewChunk) world.getChunk(x, z)).setIntBiomeArray(Arrays.copyOf(intBiomeArray, intBiomeArray.length)); |
| 46 | + MessageManager.CHANNEL.sendToAllTracking(new BiomeArrayMessage(x, z, Arrays.copyOf(intBiomeArray, intBiomeArray.length)), new NetworkRegistry.TargetPoint(world.provider.getDimension(), coord.getX(), coord.getY(), coord.getZ(), 256)); |
| 47 | + count++; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + sender.sendMessage(new TextComponentTranslation("biometweaker.msg.setbiome.chunksuccess.text", count, gen.getBiomeName()).setStyle(new Style().setColor(TextFormatting.GOLD))); |
| 52 | + |
| 53 | + ci.cancel(); |
| 54 | + } |
| 55 | +} |
0 commit comments