Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
refactor mixins into toggleable modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mist475 committed Dec 18, 2023
1 parent 345ece9 commit 8d8dd53
Show file tree
Hide file tree
Showing 83 changed files with 1,562 additions and 1,359 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/prupe/mcpatcher/cc/ColorizeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ public static boolean colorizeBlock(Block block) {
public static boolean colorizeBlock(Block block, int metadata) {
IColorMap colorMap = findColorMap(block, metadata);
if (colorMap == null) {
RenderBlocksUtils.setupColorMultiplier(block, metadata, false);
RenderBlocksUtils.setupColorMultiplier(block, false);
return false;
} else {
RenderBlocksUtils.setupColorMultiplier(block, metadata, true);
RenderBlocksUtils.setupColorMultiplier(block, true);
blockColor = colorMap.getColorMultiplier();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void setupColorMultiplier(Block block, IBlockAccess blockAccess, i
}
}

public static void setupColorMultiplier(Block block, int metadata, boolean useColor) {
public static void setupColorMultiplier(Block block, boolean useColor) {
if (block == grassBlock || !useColor) {
colorMultiplierType[0] = NONCOLOR;
colorMultiplierType[2] = NONCOLOR;
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/mist475/mcpatcherforge/asm/AsmTransformers.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.List;
import java.util.function.Supplier;

import com.prupe.mcpatcher.Config;
import com.prupe.mcpatcher.MCPatcherUtils;

import cpw.mods.fml.relauncher.FMLLaunchHandler;
import mist475.mcpatcherforge.core.MCPatcherForgeCore;

Expand All @@ -13,9 +16,9 @@
*/
public enum AsmTransformers {

RENDERBLOCKS("RenderBlocks transformer", () -> true, Side.CLIENT,
"mist475.mcpatcherforge.asm.RenderBlocksTransformer"),
WORLDRENDERER("RenderBlocks transformer", () -> true, Side.CLIENT,
RENDERBLOCKS("RenderBlocks transformer", () -> Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "enabled", true),
Side.CLIENT, "mist475.mcpatcherforge.asm.RenderBlocksTransformer"),
WORLDRENDERER("WorldRenderer transformer", () -> true, Side.CLIENT,
"mist475.mcpatcherforge.asm.WorldRendererTransformer");

private final Supplier<Boolean> applyIf;
Expand Down
235 changes: 150 additions & 85 deletions src/main/java/mist475/mcpatcherforge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,158 @@
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.prupe.mcpatcher.Config;
import com.prupe.mcpatcher.MCPatcherUtils;

import cpw.mods.fml.relauncher.FMLLaunchHandler;

// Adapted from Hodgepodge
public enum Mixins {

BASE_MOD(new Builder("All the default mixins!").setSide(Side.CLIENT)
BASE_MOD(new Builder("Base mod (can't be disabled, sorry)").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(() -> true)
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses(
"block.material.MixinMapColor",

"block.MixinBlock",
"block.MixinBlockDoublePlant",
"block.MixinBlockGrass",
"block.MixinBlockLeaves",
"block.MixinBlockLilyPad",
"block.MixinBlockLiquid",
"block.MixinBlockMycelium",
"block.MixinBlockOldLeaf",
"block.MixinBlockRedstoneWire",
"block.MixinBlockReed",
"block.MixinBlockStem",
"block.MixinBlockTallGrass",
"block.MixinBlockVine",

"client.gui.MixinFontRenderer",

"client.particle.MixinEffectRenderer",
"client.particle.MixinEntityAuraFX",
"client.particle.MixinEntityBubbleFX",
"client.particle.MixinEntityDropParticleFX",
"client.particle.MixinEntityPortalFX",
"client.particle.MixinEntityRainFX",
"client.particle.MixinEntityRedDustFX",
"client.particle.MixinEntitySplashFX",
"client.particle.MixinEntitySuspendFX",

"client.renderer.entity.MixinRender",
"client.renderer.entity.MixinRenderBiped",
"client.renderer.entity.MixinRenderEnderman",
"client.renderer.entity.MixinRenderEntityLiving",
"client.renderer.entity.MixinRenderFish",
"client.renderer.entity.MixinRenderItem",
"client.renderer.entity.MixinRenderLiving",
"client.renderer.entity.MixinRenderMooshroom",
"client.renderer.entity.MixinRenderPlayer",
"client.renderer.entity.MixinRenderSheep",
"client.renderer.entity.MixinRenderSnowball",
"client.renderer.entity.MixinRenderSnowMan",
"client.renderer.entity.MixinRenderSpider",
"client.renderer.entity.MixinRenderWolf",
"client.renderer.entity.MixinRenderXPOrb",

"client.renderer.texture.MixinAbstractTexture",
"client.renderer.texture.MixinTextureAtlasSprite",
"client.renderer.texture.MixinTextureClock",
"client.renderer.texture.MixinTextureCompass",
"client.renderer.texture.MixinTextureManager",
"client.renderer.texture.MixinTextureMap",

"client.renderer.tileentity.MixinTileEntitySignRenderer",

"client.renderer.MixinEntityRenderer",
"client.renderer.MixinItemRenderer",
"client.renderer.renderblocks.MixinRenderBlocks",
"client.renderer.renderblocks.MixinRenderBlocksRenderBlockLiquid",
"client.renderer.MixinRenderGlobal",
"client.renderer.MixinWorldRenderer",

"client.resources.MixinSimpleReloadableResourceManager",

"client.MixinMinecraft",

"entity.MixinEntityList",
"entity.MixinEntityLivingBase",

"item.crafting.MixinRecipesArmorDyes",

"item.MixinItem",
"item.MixinItemArmor",
"item.MixinItemBlock",
"item.MixinItemMonsterPlacer",

"nbt.MixinNBTTagCompound",
"nbt.MixinNBTTagList",

"potion.MixinPotion",
"potion.MixinPotionHelper",

"world.MixinWorld",
"world.MixinWorldProvider",
"world.MixinWorldProviderEnd",
"world.MixinWorldProviderHell"));
"base.MixinBlockGrass",
"base.MixinBlockMycelium",

"base.MixinAbstractTexture",
"base.MixinTextureAtlasSprite",

"base.MixinSimpleReloadableResourceManager",

"base.MixinMinecraft",

"renderpass.MixinEntityRenderer",
"renderpass.MixinRenderBlocks",
"renderpass.MixinRenderGlobal",
"renderpass.MixinWorldRenderer")

),

CUSTOM_COLOURS(new Builder("Custom colors").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(() -> Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "enabled", true))
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses(
addPrefix(
"cc.",
"block.material.MixinMapColor",

"block.MixinBlock",
"block.MixinBlockDoublePlant",
"block.MixinBlockGrass",
"block.MixinBlockLeaves",
"block.MixinBlockLilyPad",
"block.MixinBlockLiquid",
"block.MixinBlockOldLeaf",
"block.MixinBlockRedstoneWire",
"block.MixinBlockReed",
"block.MixinBlockStem",
"block.MixinBlockTallGrass",
"block.MixinBlockVine",

"client.particle.MixinEntityAuraFX",
"client.particle.MixinEntityBubbleFX",
"client.particle.MixinEntityDropParticleFX",
"client.particle.MixinEntityPortalFX",
"client.particle.MixinEntityRainFX",
"client.particle.MixinEntityRedDustFX",
"client.particle.MixinEntitySplashFX",
"client.particle.MixinEntitySuspendFX",

"client.renderer.entity.MixinRenderWolf",
"client.renderer.entity.MixinRenderXPOrb",

"client.renderer.tileentity.MixinTileEntitySignRenderer",

"client.renderer.MixinEntityRenderer",
"client.renderer.MixinItemRenderer",
"client.renderer.MixinRenderBlocks",
"client.renderer.MixinRenderGlobal",

"entity.MixinEntityList",

"item.crafting.MixinRecipesArmorDyes",

"item.MixinItemArmor",
"item.MixinItemBlock",
"item.MixinItemMonsterPlacer",

"potion.MixinPotion",
"potion.MixinPotionHelper",

"world.MixinWorld",
"world.MixinWorldProvider",
"world.MixinWorldProviderEnd",
"world.MixinWorldProviderHell"))),

CUSTOM_ITEM_TEXTURES(new Builder("Custom Item Textures").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(() -> Config.getBoolean(MCPatcherUtils.CUSTOM_ITEM_TEXTURES, "enabled", true))
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses(
addPrefix(
"cit.",
"client.renderer.entity.MixinRenderBiped",
"client.renderer.entity.MixinRenderEntityLiving",
"client.renderer.entity.MixinRenderItem",
"client.renderer.entity.MixinRenderPlayer",
"client.renderer.entity.MixinRenderSnowball",
"client.renderer.MixinItemRenderer",
"item.MixinItem",
"nbt.MixinNBTTagCompound",
"nbt.MixinNBTTagList"))),

CONNECTED_TEXTURES(new Builder("Connected Textures").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(() -> Config.getBoolean(MCPatcherUtils.CONNECTED_TEXTURES, "enabled", true))
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses("ctm.MixinRenderBlocks")),

EXTENDED_HD(new Builder("Extended hd").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(() -> Config.getBoolean(MCPatcherUtils.EXTENDED_HD, "enabled", true))
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses(
addPrefix("hd.", "MixinFontRenderer", "MixinTextureClock", "MixinTextureCompass", "MixinTextureManager"))),

RANDOM_MOBS(new Builder("Random Mobs").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(() -> Config.getBoolean(MCPatcherUtils.RANDOM_MOBS, "enabled", true))
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses(
addPrefix(
"mob.",
"MixinRender",
"MixinRenderEnderman",
"MixinRenderFish",
"MixinRenderLiving",
"MixinRenderMooshroom",
"MixinRenderSheep",
"MixinRenderSnowMan",
"MixinRenderSpider",
"MixinRenderWolf",
"MixinEntityLivingBase"))),

SKY(new Builder("Sky").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(() -> Config.getBoolean(MCPatcherUtils.BETTER_SKIES, "enabled", true))
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses(addPrefix("sky.", "MixinEffectRenderer", "MixinRenderGlobal"))),

CTM_OR_CC(new Builder("Connected textures or Custom Colors enabled").setSide(Side.CLIENT)
.setPhase(Phase.EARLY)
.setApplyIf(
() -> Config.getBoolean(MCPatcherUtils.CUSTOM_ITEM_TEXTURES, "enabled", true)
|| Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "enabled", true))
.addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses(addPrefix("ctm_cc.", "MixinRenderBlocks", "MixinTextureMap")))

;

public final String name;
public final List<String> mixinClasses;
Expand Down Expand Up @@ -213,6 +270,14 @@ && allModsLoaded(targetedMods, loadedCoreMods, loadedMods)
&& noModsLoaded(excludedMods, loadedCoreMods, loadedMods));
}

@SuppressWarnings("SimplifyStreamApiCallChains")
private static String[] addPrefix(String prefix, String... values) {
return Arrays.stream(values)
.map(s -> prefix + s)
.collect(Collectors.toList())
.toArray(new String[values.length]);
}

enum Side {
BOTH,
CLIENT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mist475.mcpatcherforge.mixins.early.client.renderer.texture;
package mist475.mcpatcherforge.mixins.early.base;

import net.minecraft.client.renderer.texture.AbstractTexture;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package mist475.mcpatcherforge.mixins.early.base;

import net.minecraft.block.Block;
import net.minecraft.block.BlockGrass;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;

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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.prupe.mcpatcher.mal.block.RenderBlocksUtils;

@Mixin(BlockGrass.class)
public class MixinBlockGrass {

@Shadow
private IIcon field_149991_b;

@Inject(
method = "getIcon(Lnet/minecraft/world/IBlockAccess;IIII)Lnet/minecraft/util/IIcon;",
at = @At("HEAD"),
cancellable = true)
private void modifyGetIcon(IBlockAccess worldIn, int x, int y, int z, int side, CallbackInfoReturnable<IIcon> cir) {
final IIcon grassTexture = RenderBlocksUtils
.getGrassTexture((Block) (Object) this, worldIn, x, y, z, side, this.field_149991_b);
if (grassTexture != null) {
cir.setReturnValue(grassTexture);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mist475.mcpatcherforge.mixins.early.block;
package mist475.mcpatcherforge.mixins.early.base;

import net.minecraft.block.Block;
import net.minecraft.block.BlockMycelium;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mist475.mcpatcherforge.mixins.early.client;
package mist475.mcpatcherforge.mixins.early.base;

import java.io.File;
import java.io.IOException;
Expand All @@ -22,6 +22,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.google.common.collect.Multimap;
import com.prupe.mcpatcher.Config;
import com.prupe.mcpatcher.MCPatcherUtils;
import com.prupe.mcpatcher.cc.Colorizer;
import com.prupe.mcpatcher.cit.CITUtils;
Expand Down Expand Up @@ -59,10 +60,18 @@ private void modifyConstructor(Session sessionIn, int displayWidth, int displayH
private void modifyStartGame1(CallbackInfo ci) {
TileLoader.init();
CTMUtils.reset();
CITUtils.init();
FontUtils.init();
MobRandomizer.init();
Colorizer.init();
if (Config.getBoolean(MCPatcherUtils.CUSTOM_ITEM_TEXTURES, "enabled", true)) {
CITUtils.init();
}
if (Config.getBoolean(MCPatcherUtils.EXTENDED_HD, "enabled", true)) {
FontUtils.init();
}
if (Config.getBoolean(MCPatcherUtils.RANDOM_MOBS, "enabled", true)) {
MobRandomizer.init();
}
if (Config.getBoolean(MCPatcherUtils.CUSTOM_COLORS, "enabled", true)) {
Colorizer.init();
}
}

@Inject(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mist475.mcpatcherforge.mixins.early.client.resources;
package mist475.mcpatcherforge.mixins.early.base;

import net.minecraft.client.resources.SimpleReloadableResourceManager;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mist475.mcpatcherforge.mixins.early.client.renderer.texture;
package mist475.mcpatcherforge.mixins.early.base;

import java.util.List;

Expand Down
Loading

0 comments on commit 8d8dd53

Please sign in to comment.