Skip to content

Commit

Permalink
Fix Gambling Style compatibility + Config option for new villager screen
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkcolour committed Mar 28, 2022
1 parent 60ff5cc commit 731abbf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ dependencies {
// Stuff I care about
implementation(fg.deobf(curse("enchantment_descriptions", 250419, 2689502)))
implementation(fg.deobf(curse("enchantment_descriptions_sources", 250419, 2689503)))
implementation(fg.deobf(curse("fluidlogged_api", 485654, 3698755)))
compileOnly(fg.deobf(curse("fluidlogged_api", 485654, 3698755)))
implementation(fg.deobf(curse("biomes_o_plenty", 220318, 2842510)))
implementation("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.19.548")
implementation(fg.deobf("mezz.jei:jei_1.12.2:4.15.0.+"))
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/thedarkcolour/futuremc/FutureMC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ object FutureMC {
@EventHandler
fun postInit(event: FMLPostInitializationEvent) {
EntityBee.FLOWERS.removeIf { state ->
state.material == Material.AIR // try to fix #281
state.material == Material.AIR || !ForgeRegistries.BLOCKS.containsValue(state.block) // try to fix #281
}

Biomes.PLAINS.addFlower(FBlocks.CORNFLOWER.defaultState, 5)
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/thedarkcolour/futuremc/asm/CoreTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
//case "net.minecraft.client.renderer.RenderItem":
// return ASMUtil.patchRenderItem(basicClass);

case "com.fuzs.gamblingstyle.handler.OpenContainerHandler":
return transformOpenContainerHandler(basicClass);

case "net.minecraft.block.BlockPistonBase":
try {
Class.forName("vazkii.quark.base.asm.LoadingPlugin");
Expand Down Expand Up @@ -126,6 +129,34 @@ private static byte[] transformBO3Loader(byte[] basicClass) {
return ASMUtil.compile(classNode);
}

private static byte[] transformOpenContainerHandler(byte[] basicClass) {
ClassNode classNode = ASMUtil.createClassNode(basicClass);
MethodNode mv = ASMUtil.findMethod(classNode, "onContainerOpen", "onContainerOpen", null);

LabelNode label = null;

try {
label = (LabelNode) mv.instructions.getFirst();
} catch (ClassCastException e) {
for (int i = 0; i < 10; i++) {
AbstractInsnNode insn = mv.instructions.get(i);
System.out.println(insn.getClass() + ": " + insn.getOpcode());
}
}

InsnList list = new InsnList();
list.add(new LabelNode(new Label()));
list.add(new FieldInsnNode(GETSTATIC, "thedarkcolour/futuremc/config/FConfig", "INSTANCE", "Lthedarkcolour/futuremc/config/FConfig;"));
list.add(new MethodInsnNode(INVOKEVIRTUAL, "thedarkcolour/futuremc/config/FConfig", "getVillageAndPillage", "()Lthedarkcolour/futuremc/config/FConfig$VillageAndPillage;", false));
list.add(new FieldInsnNode(GETFIELD, "thedarkcolour/futuremc/config/FConfig$VillageAndPillage", "newVillagerGui", "Z"));
list.add(new JumpInsnNode(IFEQ, label));
list.add(new InsnNode(RETURN));

mv.instructions.insertBefore(label, list);

return ASMUtil.compile(classNode);
}

private static byte[] patchEntityRenderer(byte[] basicClass) {
// fix incompatibility with vivecraft?
if (Compat.checkVivecraft()) return basicClass;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/thedarkcolour/futuremc/config/FConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ object FConfig {
@Name("New Villager Gui Screen")
@Comment("Whether the 1.12 villager screen is replaced by FutureMC's 1.14 villager screen")
@JvmField
val newVillagerGui = true
var newVillagerGui = true

@Name("New Walls")
@Comment("Enable/disable any of the new walls from 1.14")
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/thedarkcolour/futuremc/event/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock
import net.minecraftforge.event.terraingen.BiomeEvent
import net.minecraftforge.fml.client.event.ConfigChangedEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent
import net.minecraftforge.fml.common.registry.ForgeRegistries
Expand Down Expand Up @@ -106,7 +107,7 @@ object Events {
// addListener(::onGetWaterColor)
addListener(::healIronGolem)
runOnClient { addListener(::onGuiOpen) }
addListener(::onContainerOpen)
addListener(::onContainerOpen, priority = EventPriority.HIGHEST)
runOnClient { addListener(::onModelRegistry) }
if (TODO())
addListener(::updateSwimAnimation)
Expand Down Expand Up @@ -342,14 +343,16 @@ object Events {
}

private fun onContainerOpen(event: PlayerContainerEvent.Open) {
val container = event.container
if (FConfig.villageAndPillage.newVillagerGui) {
val container = event.container

if (container is ContainerMerchant && container !is ContainerVillager) {
val player = event.entityPlayer as EntityPlayerMP
val newContainer = ContainerVillager(player.inventory, container.merchant, null)
if (container is ContainerMerchant && container !is ContainerVillager) {
val player = event.entityPlayer as EntityPlayerMP
val newContainer = ContainerVillager(player.inventory, container.merchant, null)

newContainer.windowId = container.windowId
player.openContainer = newContainer
newContainer.windowId = container.windowId
player.openContainer = newContainer
}
}
}

Expand Down

0 comments on commit 731abbf

Please sign in to comment.