forked from DimensionalDevelopment/JustEnoughIDs
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from jchung01/mod-support
Add support for various mods and falling blocks
- Loading branch information
Showing
33 changed files
with
513 additions
and
67 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
src/main/java/org/dimdev/jeid/ducks/ICustomBiomesForGeneration.java
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,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(); | ||
} |
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,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 { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/dimdev/jeid/mixin/core/network/client/MixinNetHandlerPlayClient.java
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,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; | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/dimdev/jeid/mixin/modsupport/biomestaff/MixinBiomeStaffUtil.java
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,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); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/org/dimdev/jeid/mixin/modsupport/biomestaff/MixinItemBiomeStaff.java
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,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); | ||
} | ||
} |
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
Oops, something went wrong.