Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for various mods and falling blocks #53

Merged
Merged
64 changes: 34 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,38 +126,42 @@ dependencies {
}
}

compileOnly rfg.deobf( "curse.maven:BiomesOPlenty-220318:2842510" )
compileOnly rfg.deobf( "curse.maven:twilightforest-227639:3051450" )
compileOnly rfg.deobf( "curse.maven:Thaumcraft-223628:2629023" )
compileOnly rfg.deobf( "curse.maven:AbyssalCraft-53686:3425234" )
compileOnly rfg.deobf( "curse.maven:Creeping+Nether-268104:2655432" )
compileOnly rfg.deobf( "curse.maven:GeographiCraft-76544:2497541" )
compileOnly rfg.deobf( "curse.maven:mystcraft-224599:2958490" )
compileOnly rfg.deobf( "curse.maven:HammerCore-247401:3366814" )
compileOnly rfg.deobf("curse.maven:biomes-o-plenty-220318:2842510")
compileOnly rfg.deobf("curse.maven:twilightforest-227639:3051450")
compileOnly rfg.deobf("curse.maven:thaumcraft-223628:2629023")
compileOnly rfg.deobf("curse.maven:abyssalcraft-53686:3425234")
compileOnly rfg.deobf("curse.maven:creeping-nether-268104:2655432")
compileOnly rfg.deobf("curse.maven:geographicraft-76544:2497541")
compileOnly rfg.deobf("curse.maven:mystcraft-224599:2958490")
compileOnly rfg.deobf("curse.maven:hammercore-247401:3366814")
// Advanced Rocketry 1.7.0
compileOnly rfg.deobf( "curse.maven:AdvancedRocketry-236542:3015079" )
compileOnly rfg.deobf("curse.maven:advancedrocketry-236542:3015079")
// Advanced Rocketry 2.0.0
// compileOnly rfg.deobf( "curse.maven:AdvancedRocketry-236542:4671856" )
compileOnly rfg.deobf( "curse.maven:LibVulpes-236541:3434864" )
compileOnly rfg.deobf( "curse.maven:worldedit-225608:2941712" )
compileOnly rfg.deobf( "curse.maven:journeymap-32274:2916002" )
compileOnly rfg.deobf( "curse.maven:Bookshelf-228525:2836960" )
compileOnly rfg.deobf( "curse.maven:CyclopsCore-232758:3159497" )
compileOnly rfg.deobf( "curse.maven:extrautils2-225561:2678374" )
compileOnly rfg.deobf( "curse.maven:TheBetweenlands-243363:3248202" )
compileOnly rfg.deobf( "curse.maven:TofuCraftReload-317469:3115668" )
compileOnly rfg.deobf( "curse.maven:tropicraft-254794:2713918" )
compileOnly rfg.deobf( "curse.maven:gaiadimension-302529:2724738" )
compileOnly rfg.deobf( "curse.maven:BiomeTweaker-228895:3112142" )
compileOnly rfg.deobf( "curse.maven:baubles-227083:2518667" )
compileOnly rfg.deobf( "curse.maven:Patchouli-306770:3162874" )
compileOnly rfg.deobf( "curse.maven:bewitchment-285439:3256343" )
compileOnly rfg.deobf( "curse.maven:compact-machines-224218:2707509")
compileOnly rfg.deobf( "curse.maven:moreplanets-261990:5063201" )
compileOnly rfg.deobf( "curse.maven:atum2-59621:3116599" )

compileOnly rfg.deobf( "curse.maven:CubicChunks-292243:5135427" )
compileOnly rfg.deobf( "curse.maven:RTGU-648514:4396319" )
// compileOnly rfg.deobf("curse.maven:advancedrocketry-236542:4671856")
compileOnly rfg.deobf("curse.maven:libvulpes-236541:3434864")
compileOnly rfg.deobf("curse.maven:worldedit-225608:2941712")
compileOnly rfg.deobf("curse.maven:journeymap-32274:2916002")
compileOnly rfg.deobf("curse.maven:bookshelf-228525:2836960")
compileOnly rfg.deobf("curse.maven:cyclopscore-232758:3159497")
compileOnly rfg.deobf("curse.maven:extrautils2-225561:2678374")
compileOnly rfg.deobf("curse.maven:betweenlands-243363:3248202")
compileOnly rfg.deobf("curse.maven:tofucraftreload-317469:3115668")
compileOnly rfg.deobf("curse.maven:tropicraft-254794:2713918")
compileOnly rfg.deobf("curse.maven:gaiadimension-302529:2724738")
compileOnly rfg.deobf("curse.maven:biometweaker-228895:3112142")
compileOnly rfg.deobf("curse.maven:baubles-227083:2518667")
compileOnly rfg.deobf("curse.maven:patchouli-306770:3162874")
compileOnly rfg.deobf("curse.maven:bewitchment-285439:3256343")
compileOnly rfg.deobf("curse.maven:compact-machines-224218:2707509")
compileOnly rfg.deobf("curse.maven:moreplanets-261990:5063201")
compileOnly rfg.deobf("curse.maven:atum2-59621:3116599")
compileOnly rfg.deobf("curse.maven:naturescompass-252848:2893527")
compileOnly rfg.deobf("curse.maven:biomestaff-299907:2597577")
compileOnly rfg.deobf("curse.maven:kathairis-291129:2710928")

compileOnly rfg.deobf("curse.maven:cubicchunks-292243:5135427")
// RTG+ should also work
compileOnly rfg.deobf("curse.maven:rtg-unofficial-648514:4696300")

// implementation "curse.maven:LibVulpes-236541:3801015"
// implementation "curse.maven:Baubles-227083:2518667"
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/dimdev/jeid/core/JEIDMixinLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public List<String> getMixinConfigs() {
if (Loader.isModLoaded("biomesoplenty")) {
configs.add("mixins.jeid.biomesoplenty.json");
}
if (Loader.isModLoaded("biomestaff")) {
configs.add("mixins.jeid.biomestaff.json");
}
if (Loader.isModLoaded("biometweaker")) {
configs.add("mixins.jeid.biometweaker.json");
}
Expand Down Expand Up @@ -67,12 +70,21 @@ public List<String> getMixinConfigs() {
if (Loader.isModLoaded("journeymap")) {
configs.add("mixins.jeid.journeymap.json");
}
if (Loader.isModLoaded("kathairis")) {
configs.add("mixins.jeid.kathairis.json");
}
if (Loader.isModLoaded("moreplanets")) {
configs.add("mixins.jeid.moreplanets.json");
}
if (Loader.isModLoaded("mystcraft")) {
configs.add("mixins.jeid.mystcraft.json");
}
if (Loader.isModLoaded("naturescompass")) {
configs.add("mixins.jeid.naturescompass.json");
}
if (Loader.isModLoaded("rtg")) {
configs.add("mixins.jeid.rtg.json");
}
if (Loader.isModLoaded("thaumcraft")) {
configs.add("mixins.jeid.thaumcraft.json");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.dimdev.jeid.ducks;

import net.minecraft.world.biome.Biome;

/**
* Duck interface for mixins into certain mods with custom chunk generators.
* If your mod uses a custom chunk generator and modifies the biome array returned by:
* <p>{@code this.world.getBiomeProvider().getBiomes(...)},</p>
* implement this in your IChunkGenerator.
*/
public interface ICustomBiomesForGeneration {
/**
* Returns the modified biome array (usually called {@code biomesForGeneration}).
*
* @return the modified biome array
*/
Biome[] getBiomesForGeneration();
}
10 changes: 10 additions & 0 deletions src/main/java/org/dimdev/jeid/ducks/IModSupportsJEID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.dimdev.jeid.ducks;

/**
* Duck interface for any mod that already sets up the Chunk's intBiomeArray
* in {@link net.minecraft.world.gen.IChunkGenerator#generateChunk}.
* If your mod uses a custom chunk generator and has explicit compat with JEID,
* implement this in your IChunkGenerator.
*/
public interface IModSupportsJEID {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.dimdev.jeid.mixin.core.network.client;

import net.minecraft.client.network.NetHandlerPlayClient;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Slice;

@Mixin(value = NetHandlerPlayClient.class)
public class MixinNetHandlerPlayClient {
/**
* @reason Account for JEID blockstate format (32 bits, not 16).
*/
@ModifyConstant(method = "handleSpawnObject",
slice = @Slice(
id = "fallingBlock",
from = @At(value = "NEW", target = "(Lnet/minecraft/world/World;DDDLnet/minecraft/block/state/IBlockState;)Lnet/minecraft/entity/item/EntityFallingBlock;"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getStateById(I)Lnet/minecraft/block/state/IBlockState;")
), constant = @Constant(intValue = 0xFFFF, slice = "fallingBlock"))
private int reid$getJEIDBlockstate(int constant) {
return 0xFFFFFFFF;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraftforge.fml.common.Loader;
import net.minecraft.world.gen.IChunkGenerator;

import com.llamalad7.mixinextras.sugar.Local;
import org.dimdev.jeid.ducks.ICustomBiomesForGeneration;
import org.dimdev.jeid.ducks.IModSupportsJEID;
import org.dimdev.jeid.ducks.INewChunk;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,14 +17,16 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import rtg.world.biome.BiomeProviderRTG;

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

/**
Expand All @@ -31,14 +35,21 @@ public class MixinChunkProviderServer {
*/
@Inject(method = "provideChunk", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/gen/IChunkGenerator;generateChunk(II)Lnet/minecraft/world/chunk/Chunk;"))
private void reid$initializeBiomeArray(int x, int z, CallbackInfoReturnable<Chunk> cir, @Local Chunk chunk) {
if (!Loader.isModLoaded("rtg") || !(world.getBiomeProvider() instanceof BiomeProviderRTG)) {
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]);
}
if (this.chunkGenerator instanceof IModSupportsJEID) {
return;
}
Biome[] biomes;
if (this.chunkGenerator instanceof ICustomBiomesForGeneration) {
// Some chunk generators modify the biomes beyond those returned by the BiomeProvider.
biomes = ((ICustomBiomesForGeneration) this.chunkGenerator).getBiomesForGeneration();
}
else {
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]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.dimdev.jeid.mixin.modsupport.biomestaff;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.biome.Biome;

import net.minecraftforge.common.util.Constants;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import p455w0rd.biomestaff.item.ItemBiomeStaff;
import p455w0rd.biomestaff.util.BiomeStaffUtil;

@Mixin(value = BiomeStaffUtil.class, remap = false)
public class MixinBiomeStaffUtil {
/**
* @reason Rewrite to get int biome id from NBT.
*/
@SuppressWarnings("ConstantConditions")
@Inject(method = "getBiomeFromStaff", at = @At(value = "HEAD"), cancellable = true)
private static void reid$getIntBiome(ItemStack staff, CallbackInfoReturnable<Biome> cir) {
if (staff.hasTagCompound() && staff.getTagCompound().hasKey(ItemBiomeStaff.TAG_BIOME, Constants.NBT.TAG_INT)) {
Biome biome = Biome.getBiome(staff.getTagCompound().getInteger(ItemBiomeStaff.TAG_BIOME));
cir.setReturnValue(biome);
return;
}
cir.setReturnValue(null);
}

/**
* @reason Rewrite to construct NBT based on int biome id.
*/
@Inject(method = "createTagForBiome", at = @At(value = "HEAD"), cancellable = true)
private static void reid$createIntTag(Biome biome, CallbackInfoReturnable<NBTTagCompound> cir) {
NBTTagCompound tag = new NBTTagCompound();
int biomeId = Biome.getIdForBiome(biome);
tag.setInteger(ItemBiomeStaff.TAG_BIOME, biomeId);
cir.setReturnValue(tag);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.dimdev.jeid.mixin.modsupport.biomestaff;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.util.Constants;

import com.llamalad7.mixinextras.sugar.Local;
import org.dimdev.jeid.ducks.INewChunk;
import org.dimdev.jeid.network.MessageManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import p455w0rd.biomestaff.init.ModNetworking;
import p455w0rd.biomestaff.item.ItemBiomeStaff;
import p455w0rd.biomestaff.network.PacketSyncBiomeStaff;

@Mixin(value = ItemBiomeStaff.class)
public class MixinItemBiomeStaff {
@ModifyArg(method = "onItemRightClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z"), index = 1)
private int reid$checkIntNBTKey(int original) {
return Constants.NBT.TAG_INT;
}

/**
* @reason Rewrite sneak use logic to save int biome id.
*/
@Inject(method = "onItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getChunk(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/world/chunk/Chunk;", ordinal = 0), cancellable = true)
private void reid$sneakUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ, CallbackInfoReturnable<EnumActionResult> cir,
@Local ItemStack heldStack, @Local NBTTagCompound tag) {
Chunk chunk = world.getChunk(pos);
int biomeId = ((INewChunk) chunk).getIntBiomeArray()[(pos.getZ() & 0xF) << 4 | (pos.getX() & 0xF)];
if (!tag.hasKey(ItemBiomeStaff.TAG_BIOME, Constants.NBT.TAG_INT) || tag.getInteger(ItemBiomeStaff.TAG_BIOME) != biomeId) {
tag.setInteger(ItemBiomeStaff.TAG_BIOME, biomeId);
heldStack.setTagCompound(tag);
ModNetworking.getInstance().sendTo(new PacketSyncBiomeStaff(heldStack.getTagCompound()), (EntityPlayerMP)player);
}
cir.setReturnValue(EnumActionResult.SUCCESS);
}

/**
* @reason Rewrite biome application logic to use int biome id.
*/
@Inject(method = "onItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;getByte(Ljava/lang/String;)B", ordinal = 1), cancellable = true)
private void reid$applyBiome(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ, CallbackInfoReturnable<EnumActionResult> cir,
@Local ItemStack heldStack, @Local NBTTagCompound tag, @Local(ordinal = 1) int rad) {
int toBiomeId = tag.getInteger(ItemBiomeStaff.TAG_BIOME);
for(int ix = pos.getX() - rad; ix <= pos.getX() + rad; ++ix) {
for(int iz = pos.getZ() - rad; iz <= pos.getZ() + rad; ++iz) {
Chunk chunk = world.getChunk(new BlockPos(ix, pos.getY(), iz));
int[] biomeArray = ((INewChunk) chunk).getIntBiomeArray();
int biomeIdAtPos = biomeArray[(iz & 0xF) << 4 | (ix & 0xF)];
if (biomeIdAtPos != toBiomeId) {
chunk.markDirty();
biomeArray[(iz & 0xF) << 4 | (ix & 0xF)] = toBiomeId;
}
}
}
MessageManager.sendClientsBiomeAreaChange(world, pos, rad, toBiomeId);
cir.setReturnValue(EnumActionResult.SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Arrays;
Expand All @@ -29,7 +30,18 @@ public class MixinCommandSetBiome {
JEID.LOGGER.info("setting biome at {}, {}", x, z);
// Method calls markDirty()
((INewChunk) chunk).getIntBiomeArray()[(z & 0xF) << 4 | x & 0xF] = id;
MessageManager.sendClientsBiomeChange(world, new BlockPos(x, coord.getY(), z), id);
}

@Inject(method = "execute",
slice = @Slice(
from = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/BlockPos;getX()I", ordinal = 0),
to = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/BlockPos;getX()I", ordinal = 2)
),
at = @At(value = "INVOKE", target = "Lnet/minecraft/command/ICommandSender;sendMessage(Lnet/minecraft/util/text/ITextComponent;)V"))
private void reid$sendBiomeAreaChange(MinecraftServer server, ICommandSender sender, String[] args, CallbackInfo ci,
@Local BlockPos coord, @Local World world, @Local Integer radius,
@Local(ordinal = 0) int id) {
MessageManager.sendClientsBiomeAreaChange(world, coord, radius, id);
}

@Inject(method = "execute", at = @At(value = "INVOKE", target = "Ljava/util/Arrays;fill([BB)V", remap = false))
Expand All @@ -47,6 +59,6 @@ public class MixinCommandSetBiome {
int posX = chunkX << 4;
int posZ = chunkZ << 4;
((INewChunk) world.getChunk(chunkX, chunkZ)).setIntBiomeArray(Arrays.copyOf(intBiomeArray.get(), intBiomeArray.get().length));
MessageManager.sendClientsBiomeArray(world, new BlockPos(posX, coord.getY(), posZ), Arrays.copyOf(intBiomeArray.get(), intBiomeArray.get().length));
MessageManager.sendClientsBiomeChunkChange(world, new BlockPos(posX, coord.getY(), posZ), Arrays.copyOf(intBiomeArray.get(), intBiomeArray.get().length));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MixinWorldUtils {
// Method calls getDirty()
Arrays.fill(biomeArray, Biome.getIdForBiome(biome));
if (!world.isRemote) {
MessageManager.sendClientsBiomeArray(world, pos, Arrays.copyOf(biomeArray, biomeArray.length));
MessageManager.sendClientsBiomeChunkChange(world, pos, Arrays.copyOf(biomeArray, biomeArray.length));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public abstract class MixinCorruptorAbstract {

@Redirect(method = "corruptBiome", at = @At(value = "INVOKE", target = "Lcom/cutievirus/creepingnether/entity/MessageCorruptBiome;sendMessage(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lcom/cutievirus/creepingnether/entity/CorruptorAbstract;)V"))
private void reid$sendBiomeMessage(World world, BlockPos pos, CorruptorAbstract corruptor) {
MessageManager.sendClientsBiomeChange(world, pos, Biome.getIdForBiome(getBiome()));
MessageManager.sendClientsBiomePosChange(world, pos, Biome.getIdForBiome(getBiome()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MixinWorldHelpers {
@Inject(method = "setBiome", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getChunkProvider()Lnet/minecraft/world/chunk/IChunkProvider;", remap = true), cancellable = true)
private static void reid$sendBiomeMessage(World world, BlockPos pos, Biome biome, CallbackInfo ci) {
if (!world.isRemote) {
MessageManager.sendClientsBiomeChange(world, pos, Biome.getIdForBiome(biome));
MessageManager.sendClientsBiomePosChange(world, pos, Biome.getIdForBiome(biome));
}
ci.cancel();
}
Expand Down
Loading
Loading