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.
However, the original version uses MixinBootstrap as Mixin support, while REID uses MixinBooter as Mixin support, which will cause conflicts. MixinBooter must be used for the patch to take effect.
- Loading branch information
1 parent
02ccfaa
commit 289f373
Showing
7 changed files
with
871 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.dimdev.jeid.core; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import net.minecraftforge.fml.common.Loader; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public class JEIDMixinPlugin implements IMixinConfigPlugin { | ||
|
||
private final List<String> matchingTarget = ImmutableList.of( | ||
"net.minecraft.world.chunk.Chunk", | ||
"net.minecraft.world.chunk.storage.AnvilChunkLoader", | ||
"net.minecraft.network.play.server.SPacketChunkData"); | ||
private final List<String> matchingMixin = ImmutableList.of( | ||
"org.dimdev.jeid.mixin.core.world.MixinChunk", | ||
"me.jellysquid.mods.phosphor.mixins.lighting.common.MixinChunk", | ||
"org.dimdev.jeid.mixin.core.world.MixinAnvilChunkLoader", | ||
"me.jellysquid.mods.phosphor.mixins.lighting.common.MixinAnvilChunkLoader", | ||
"org.dimdev.jeid.mixin.core.network.MixinSPacketChunkData", | ||
"me.jellysquid.mods.phosphor.mixins.lighting.common.MixinSPacketChunkData", | ||
"me.jellysquid.mods.phosphor.mixins.lighting.common.MixinChunk$Sponge", | ||
"me.jellysquid.mods.phosphor.mixins.lighting.common.MixinChunk$Vanilla"); | ||
|
||
@Override | ||
public void onLoad(String mixinPackage) { | ||
|
||
} | ||
|
||
@Override | ||
public String getRefMapperConfig() { | ||
// if (!Loader.isModLoaded("phosphor-lighting")){ | ||
// return "mixins.jeid.refmap.json"; | ||
// } | ||
return "mixins.jeid.refmap.json"; | ||
} | ||
|
||
@Override | ||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
if (Loader.isModLoaded("phosphor-lighting")) { | ||
if (matchingTarget.contains(targetClassName) && matchingMixin.contains(mixinClassName)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { | ||
|
||
} | ||
|
||
@Override | ||
public List<String> getMixins() { | ||
if (Loader.isModLoaded("phosphor-lighting")){ | ||
return ImmutableList.of( | ||
"org.dimdev.jeid.mixin.modsupport.phosphor.MixinChunk", | ||
"org.dimdev.jeid.mixin.modsupport.phosphor.MixinAnvilChunkLoader", | ||
"org.dimdev.jeid.mixin.modsupport.phosphor.MixinSPacketChunkData", | ||
"org.dimdev.jeid.mixin.modsupport.phosphor.MixinChunk$Vanilla", | ||
"org.dimdev.jeid.mixin.modsupport.phosphor.MixinChunk$Sponge"); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { | ||
|
||
} | ||
|
||
@Override | ||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { | ||
|
||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/org/dimdev/jeid/mixin/modsupport/phosphor/MixinAnvilChunkLoader.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,115 @@ | ||
package org.dimdev.jeid.mixin.modsupport.phosphor; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import me.jellysquid.mods.phosphor.api.IChunkLightingData; | ||
import me.jellysquid.mods.phosphor.api.ILightingEngineProvider; | ||
import me.jellysquid.mods.phosphor.mod.world.lighting.LightingHooks; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.chunk.NibbleArray; | ||
import net.minecraft.world.chunk.storage.AnvilChunkLoader; | ||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage; | ||
import org.dimdev.jeid.JEID; | ||
import org.dimdev.jeid.ducks.INewBlockStateContainer; | ||
import org.dimdev.jeid.ducks.INewChunk; | ||
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.Redirect; | ||
import org.spongepowered.asm.mixin.injection.Slice; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(AnvilChunkLoader.class) | ||
public class MixinAnvilChunkLoader { | ||
/** | ||
* @reason Read palette from NBT for JustEnoughIDs BlockStateContainers. | ||
*/ | ||
@Inject(method = "readChunkFromNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B", ordinal = 0)) | ||
private void reid$readPaletteNBT(CallbackInfoReturnable<Chunk> cir, @Local(ordinal = 1) NBTTagCompound storageNBT, @Local ExtendedBlockStorage extendedBlockStorage) { | ||
int[] palette = storageNBT.hasKey("Palette", 11) ? storageNBT.getIntArray("Palette") : null; | ||
((INewBlockStateContainer) extendedBlockStorage.getData()).setTemporaryPalette(palette); | ||
NibbleArray add2 = storageNBT.hasKey("Add2", 7) ? new NibbleArray(storageNBT.getByteArray("Add2")) : null; | ||
((INewBlockStateContainer) extendedBlockStorage.getData()).setLegacyAdd2(add2); | ||
} | ||
|
||
/** | ||
* @reason Write palette to NBT for JustEnoughIDs BlockStateContainers. | ||
*/ | ||
@Inject(method = "writeChunkToNBT", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/chunk/BlockStateContainer;getDataForNBT([BLnet/minecraft/world/chunk/NibbleArray;)Lnet/minecraft/world/chunk/NibbleArray;", ordinal = 0)) | ||
private void reid$writePaletteNBT(CallbackInfo ci, @Local ExtendedBlockStorage extendedBlockStorage, @Local(ordinal = 1) NBTTagCompound storageNBT) { | ||
int[] palette = ((INewBlockStateContainer) extendedBlockStorage.getData()).getTemporaryPalette(); | ||
if (palette != null) storageNBT.setIntArray("Palette", palette); | ||
} | ||
|
||
/** | ||
* @reason Read int biome array from NBT if it's there. | ||
*/ | ||
@Inject(method = "readChunkFromNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z", ordinal = 1)) | ||
private void reid$readBiomeArray(World world, NBTTagCompound nbt, CallbackInfoReturnable<Chunk> cir, @Local Chunk chunk) { | ||
INewChunk newChunk = (INewChunk) chunk; | ||
if (nbt.hasKey("Biomes", 11)) { | ||
newChunk.setIntBiomeArray(nbt.getIntArray("Biomes")); | ||
} else { | ||
// Convert old chunks | ||
int[] intBiomeArray = new int[256]; | ||
int index = 0; | ||
for (byte b : nbt.getByteArray("Biomes")) { | ||
intBiomeArray[index++] = b & 0xFF; | ||
} | ||
newChunk.setIntBiomeArray(intBiomeArray); | ||
} | ||
} | ||
|
||
/** | ||
* @reason Save the correct biome array type | ||
*/ | ||
@Redirect(method = "writeChunkToNBT", | ||
slice = @Slice( | ||
id = "nbtBiomes", | ||
from = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;setTag(Ljava/lang/String;Lnet/minecraft/nbt/NBTBase;)V"), | ||
to = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;setHasEntities(Z)V") | ||
), at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V", ordinal = 0, slice = "nbtBiomes")) | ||
private void reid$writeBiomeArray(NBTTagCompound instance, String key, byte[] value, Chunk chunkIn) { | ||
if (!key.equals("Biomes")) { | ||
throw new AssertionError(JEID.MODID + " :: Sliced target setByteArray isn't \"Biomes\""); | ||
} | ||
instance.setIntArray(key, ((INewChunk) chunkIn).getIntBiomeArray()); | ||
} | ||
|
||
/** | ||
* @reason Disable default biome array save logic. | ||
*/ | ||
@Redirect(method = "writeChunkToNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B", ordinal = 0)) | ||
private byte[] reid$defaultWriteBiomeArray(Chunk chunk) { | ||
return new byte[0]; | ||
} | ||
|
||
@Inject( | ||
method = {"saveChunk"}, | ||
at = {@At("HEAD")} | ||
) | ||
private void onConstructed(World world, Chunk chunkIn, CallbackInfo callbackInfo) { | ||
((ILightingEngineProvider)world).getLightingEngine().processLightUpdates(); | ||
} | ||
|
||
@Inject( | ||
method = {"readChunkFromNBT"}, | ||
at = {@At("RETURN")} | ||
) | ||
private void onReadChunkFromNBT(World world, NBTTagCompound compound, CallbackInfoReturnable<Chunk> cir) { | ||
Chunk chunk = (Chunk)cir.getReturnValue(); | ||
LightingHooks.readNeighborLightChecksFromNBT(chunk, compound); | ||
((IChunkLightingData)chunk).setLightInitialized(compound.getBoolean("LightPopulated")); | ||
} | ||
|
||
@Inject( | ||
method = {"writeChunkToNBT"}, | ||
at = {@At("RETURN")} | ||
) | ||
private void onWriteChunkToNBT(Chunk chunk, World world, NBTTagCompound compound, CallbackInfo ci) { | ||
LightingHooks.writeNeighborLightChecksToNBT(chunk, compound); | ||
compound.setBoolean("LightPopulated", ((IChunkLightingData)chunk).isLightInitialized()); | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
src/main/java/org/dimdev/jeid/mixin/modsupport/phosphor/MixinChunk$Sponge.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,129 @@ | ||
package org.dimdev.jeid.mixin.modsupport.phosphor; | ||
|
||
import me.jellysquid.mods.phosphor.mod.world.lighting.LightingHooks; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage; | ||
import org.spongepowered.asm.mixin.Dynamic; | ||
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.ModifyVariable; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.Slice; | ||
|
||
@Mixin(Chunk.class) | ||
public abstract class MixinChunk$Sponge { | ||
private static final String SET_BLOCK_STATE_SPONGE = "bridge$setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/block/state/IBlockState;Lorg/spongepowered/api/world/BlockChangeFlag;)Lnet/minecraft/block/state/IBlockState;"; | ||
@Shadow | ||
@Final | ||
private World world; | ||
|
||
@Shadow | ||
public int x; | ||
@Final | ||
@Shadow | ||
public int z; | ||
|
||
private static final int WIZARD_MAGIC = 694698818; | ||
|
||
public MixinChunk$Sponge() { | ||
} | ||
|
||
@Redirect( | ||
method = {"bridge$setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/block/state/IBlockState;Lorg/spongepowered/api/world/BlockChangeFlag;)Lnet/minecraft/block/state/IBlockState;"}, | ||
at = @At( | ||
value = "NEW", | ||
args = {"class=net/minecraft/world/chunk/storage/ExtendedBlockStorage"} | ||
), | ||
expect = 0 | ||
) | ||
@Dynamic | ||
private ExtendedBlockStorage setBlockStateCreateSectionSponge(int y, boolean storeSkylight) { | ||
return this.initSection(y, storeSkylight); | ||
} | ||
|
||
private ExtendedBlockStorage initSection(int y, boolean storeSkylight) { | ||
ExtendedBlockStorage storage = new ExtendedBlockStorage(y, storeSkylight); | ||
LightingHooks.initSkylightForSection(this.world, new Chunk(this.world, this.x, this.z), storage); | ||
return storage; | ||
} | ||
|
||
@ModifyVariable( | ||
method = {"bridge$setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/block/state/IBlockState;Lorg/spongepowered/api/world/BlockChangeFlag;)Lnet/minecraft/block/state/IBlockState;"}, | ||
at = @At( | ||
value = "LOAD", | ||
ordinal = 0 | ||
), | ||
index = 14, | ||
name = {"requiresNewLightCalculations"}, | ||
slice = @Slice( | ||
from = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;get(III)Lnet/minecraft/block/state/IBlockState;" | ||
), | ||
to = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/Chunk;generateSkylightMap()V" | ||
) | ||
), | ||
allow = 1 | ||
) | ||
@Dynamic | ||
private boolean setBlockStateInjectGenerateSkylightMapVanilla(boolean generateSkylight) { | ||
return false; | ||
} | ||
|
||
@ModifyVariable( | ||
method = {"bridge$setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/block/state/IBlockState;Lorg/spongepowered/api/world/BlockChangeFlag;)Lnet/minecraft/block/state/IBlockState;"}, | ||
at = @At( | ||
value = "LOAD", | ||
ordinal = 1 | ||
), | ||
index = 13, | ||
name = {"newBlockLightOpacity"}, | ||
slice = @Slice( | ||
from = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/Chunk;relightBlock(III)V", | ||
ordinal = 1 | ||
), | ||
to = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/Chunk;propagateSkylightOcclusion(II)V" | ||
) | ||
), | ||
allow = 1 | ||
) | ||
@Dynamic | ||
private int setBlockStatePreventPropagateSkylightOcclusion1(int generateSkylight) { | ||
return 694698818; | ||
} | ||
|
||
@ModifyVariable( | ||
method = {"bridge$setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/block/state/IBlockState;Lorg/spongepowered/api/world/BlockChangeFlag;)Lnet/minecraft/block/state/IBlockState;"}, | ||
at = @At( | ||
value = "LOAD", | ||
ordinal = 0 | ||
), | ||
index = 24, | ||
name = {"postNewBlockLightOpacity"}, | ||
slice = @Slice( | ||
from = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/Chunk;relightBlock(III)V", | ||
ordinal = 1 | ||
), | ||
to = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/world/chunk/Chunk;propagateSkylightOcclusion(II)V" | ||
) | ||
), | ||
allow = 1 | ||
) | ||
@Dynamic | ||
private int setBlockStatePreventPropagateSkylightOcclusion2(int generateSkylight) { | ||
return 694698818; | ||
} | ||
} |
Oops, something went wrong.