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

Small Cleanup (mostly @Share / @Local) #276

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.network.NetworkRegistry;
Expand All @@ -21,8 +24,6 @@
@Mixin(value = { OpenGuiHandler.class })
public abstract class MixinOpenGuiHandler extends SimpleChannelInboundHandler<FMLMessage.OpenGui> {

boolean openGuiSuccess = false;

/*
* Copy the logic from player.openGui to explicitly check if the getLocalGuiContainer failed
*/
Expand All @@ -32,14 +33,16 @@ public abstract class MixinOpenGuiHandler extends SimpleChannelInboundHandler<FM
value = "INVOKE",
target = "Lnet/minecraft/entity/player/EntityPlayer;openGui(Ljava/lang/Object;ILnet/minecraft/world/World;III)V"),
remap = false)
public void hodgepodge$openGui(EntityPlayer player, Object mod, int modGuiId, World world, int x, int y, int z) {
this.openGuiSuccess = false;
public void hodgepodge$openGui(EntityPlayer player, Object mod, int modGuiId, World world, int x, int y, int z,
@Share("openGuiSuccess") LocalBooleanRef openGuiSuccess) {
ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
Object guiContainer = NetworkRegistry.INSTANCE.getLocalGuiContainer(mc, player, modGuiId, world, x, y, z);
if (guiContainer != null) {
FMLCommonHandler.instance().showGuiScreen(guiContainer);
this.openGuiSuccess = true;
openGuiSuccess.set(true);
return;
}
openGuiSuccess.set(false);
}

/*
Expand All @@ -49,7 +52,7 @@ public abstract class MixinOpenGuiHandler extends SimpleChannelInboundHandler<FM
method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lcpw/mods/fml/common/network/internal/FMLMessage$OpenGui;)V",
at = @At(value = "FIELD", target = "Lnet/minecraft/inventory/Container;windowId:I", opcode = PUTFIELD),
cancellable = true)
public void hodgepodge$dontSetWindowId(CallbackInfo ci) {
if (!this.openGuiSuccess) ci.cancel();
public void hodgepodge$dontSetWindowId(CallbackInfo ci, @Share("openGuiSuccess") LocalBooleanRef openGuiSuccess) {
if (!openGuiSuccess.get()) ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,7 +16,7 @@
public class MixinContainer {

@Shadow
public List inventorySlots;
public List<Slot> inventorySlots;

@Inject(method = "putStacksInSlots([Lnet/minecraft/item/ItemStack;)V", at = @At(value = "HEAD"), cancellable = true)
public void hodgepodge$checkStacksSize(ItemStack[] p_75131_1_, CallbackInfo ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@SuppressWarnings({ "unused", "rawtypes" })
@Mixin(EntityLivingBase.class)
public abstract class MixinEntityLivingBase_FixPotionException extends Entity {

@Shadow
@Final
private HashMap activePotionsMap;
private HashMap<Integer, PotionEffect> activePotionsMap;

@Shadow
private boolean potionsNeedUpdate;
Expand All @@ -39,12 +38,12 @@ private MixinEntityLivingBase_FixPotionException(World p_i1594_1_) {
*/
@Overwrite
protected void updatePotionEffects() {
Iterator iterator = this.activePotionsMap.keySet().iterator();
Iterator<Integer> iterator = this.activePotionsMap.keySet().iterator();

try {
while (iterator.hasNext()) {
Integer integer = (Integer) iterator.next();
PotionEffect potioneffect = (PotionEffect) this.activePotionsMap.get(integer);
Integer integer = iterator.next();
PotionEffect potioneffect = this.activePotionsMap.get(integer);

if (!potioneffect.onUpdate(((EntityLivingBase) (Object) this))) {
if (!this.worldObj.isRemote) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
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 com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import com.mitchej123.hodgepodge.Common;

@Mixin(EntityPlayer.class)
public abstract class MixinEntityPlayer {

@Unique
private int itemEntityCounter;

@Shadow
protected abstract void collideWithPlayer(Entity p_71044_1_);

Expand All @@ -30,8 +28,9 @@ public abstract class MixinEntityPlayer {
value = "INVOKE",
target = "Lnet/minecraft/world/World;getEntitiesWithinAABBExcludingEntity(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/AxisAlignedBB;)Ljava/util/List;",
shift = At.Shift.AFTER))
public void hodgepodge$resetItemCounter(CallbackInfo ci) {
itemEntityCounter = 0;
public void hodgepodge$resetItemCounter(CallbackInfo ci,
@Share("itemEntityCounter") LocalIntRef itemEntityCounter) {
itemEntityCounter.set(0);
}

@Redirect(
Expand All @@ -43,12 +42,13 @@ public abstract class MixinEntityPlayer {
from = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;getEntitiesWithinAABBExcludingEntity(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/AxisAlignedBB;)Ljava/util/List;")))
public void hodgepodge$ThrottleItemPickupEvent(EntityPlayer instance, Entity entity) {
public void hodgepodge$ThrottleItemPickupEvent(EntityPlayer instance, Entity entity,
@Share("itemEntityCounter") LocalIntRef itemEntityCounter) {
if (entity instanceof EntityItem) {
if (itemEntityCounter < Common.config.itemStacksPickedUpPerTick) {
if (itemEntityCounter.get() < Common.config.itemStacksPickedUpPerTick) {
this.collideWithPlayer(entity);
}
itemEntityCounter++;
itemEntityCounter.set(itemEntityCounter.get() + 1);
return;
}
this.collideWithPlayer(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@SuppressWarnings("unused")
@Mixin(FontRenderer.class)
public abstract class MixinFontRenderer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ public abstract class MixinFurnaceRecipes {
* replacement hash map and an ItemStack hashing strategy 2) No longer looping over every. single. recipe. in the
* list and using the .get()
*/
@SuppressWarnings("rawtypes")
@Shadow
private Map smeltingList = new ItemStackMap<ItemStack>(false);
private Map<ItemStack, ItemStack> smeltingList = new ItemStackMap<ItemStack>(false);

@SuppressWarnings("rawtypes")
@Shadow
private Map experienceList = new ItemStackMap<Float>(false);
private Map<ItemStack, Float> experienceList = new ItemStackMap<Float>(false);

/**
* @author mitchej123
* @reason Significantly faster Inspired by later versions of forge
*/
@SuppressWarnings("unchecked")
@Overwrite
public void func_151394_a /* addSmeltingRecipe */(ItemStack input, ItemStack stack, float experience) {
if (getSmeltingResult(input) != null) {
Expand All @@ -59,7 +56,6 @@ public ItemStack getSmeltingResult(ItemStack stack) {
* @author mitchej123
* @reason Significantly faster
*/
@SuppressWarnings("unchecked")
@Overwrite
public float func_151398_b /* getSmeltingExperience */(ItemStack stack) {
if (stack == null || stack.getItem() == null) return 0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class MixinGuiContainerCreative extends GuiContainer {
@Shadow
private static int selectedTabIndex;

public MixinGuiContainerCreative(Container p_i1072_1_) {
private MixinGuiContainerCreative(Container p_i1072_1_) {
super(p_i1072_1_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import com.mitchej123.hodgepodge.client.chat.ChatHandler;

@Mixin(GuiNewChat.class)
Expand All @@ -30,24 +31,20 @@ public class MixinGuiNewChat_CompactChat {
@Final
private List<ChatLine> field_146253_i; // drawnChatLines

@Unique
private boolean hodgepodge$deleteMessage;

@Inject(method = "func_146237_a", at = @At("HEAD"))
private void hodgepodge$compactChat(IChatComponent imsg, int chatLineId, int updateCounter, boolean refresh,
CallbackInfo ci) {
this.hodgepodge$deleteMessage = !refresh && ChatHandler.tryCompactMessage(imsg, this.chatLines)
&& chatLineId == 0;
CallbackInfo ci, @Share("deleteMessage") LocalBooleanRef deleteMessage) {
deleteMessage.set(!refresh && ChatHandler.tryCompactMessage(imsg, this.chatLines) && chatLineId == 0);
}

@Inject(
method = "func_146237_a",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatOpen()Z"),
locals = LocalCapture.CAPTURE_FAILSOFT)
private void hodgepodge$deletePrevious(IChatComponent imsg, int chatLineId, int updateCounter, boolean refresh,
CallbackInfo ci, int k, int l, ChatComponentText chatcomponenttext,
ArrayList<ChatComponentText> arraylist) {
if (!this.hodgepodge$deleteMessage) return;
CallbackInfo ci, int k, int l, ChatComponentText chatcomponenttext, ArrayList<ChatComponentText> arraylist,
@Share("deleteMessage") LocalBooleanRef deleteMessage) {
if (!deleteMessage.get()) return;
if (this.chatLines.isEmpty()) return;
this.chatLines.remove(0);
for (int i = 0; i < arraylist.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,14 @@
import net.minecraft.client.gui.GuiNewChat;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import com.llamalad7.mixinextras.sugar.Local;

@Mixin(GuiNewChat.class)
public class MixinGuiNewChat_FixColorWrapping {

@Unique
private String hodgepodge$s1;

@ModifyVariable(
method = "func_146237_a",
at = @At(
value = "NEW",
target = "(Ljava/lang/String;)Lnet/minecraft/util/ChatComponentText;",
ordinal = 2,
shift = At.Shift.BEFORE),
name = "s1")
private String hodgepodge$captureS1(String s1) {
this.hodgepodge$s1 = s1;
return s1;
}

@ModifyVariable(
method = "func_146237_a",
at = @At(
Expand All @@ -34,8 +19,8 @@ public class MixinGuiNewChat_FixColorWrapping {
ordinal = 2,
shift = At.Shift.BEFORE),
name = "s2")
private String hodgepodge$fixColorWrapping(String s2) {
return FontRendererAccessor.callGetFormatFromString(this.hodgepodge$s1) + s2;
private String hodgepodge$fixColorWrapping(String s2, @Local(name = "s1") String s1) {
return FontRendererAccessor.callGetFormatFromString(s1) + s2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
import org.spongepowered.asm.mixin.injection.Redirect;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import com.mitchej123.hodgepodge.Common;
import com.mitchej123.hodgepodge.util.RomanNumerals;

@Mixin(InventoryEffectRenderer.class)
public class MixinInventoryEffectRenderer_FixPotionEffectNumerals {

private int hodgepodge$potionAmplifierLevel;

@ModifyExpressionValue(
method = "func_147044_g",
at = @At(value = "INVOKE", target = "Lnet/minecraft/potion/PotionEffect;getAmplifier()I", ordinal = 0))
private int hodgepodge$skipOriginalCode(int amplifier) {
this.hodgepodge$potionAmplifierLevel = amplifier;
private int hodgepodge$skipOriginalCode(int amplifier,
@Share("potionAmplifierLevel") LocalIntRef potionAmplifierLevel) {
potionAmplifierLevel.set(amplifier);
return 1;
}

Expand All @@ -30,15 +31,16 @@ public class MixinInventoryEffectRenderer_FixPotionEffectNumerals {
value = "INVOKE",
target = "Lnet/minecraft/client/resources/I18n;format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;",
ordinal = 1))
private String hodgepodge$addRomanNumeral(String string, Object... objects) {
if (this.hodgepodge$potionAmplifierLevel > 0) {
private String hodgepodge$addRomanNumeral(String string, Object[] objects,
@Share("potionAmplifierLevel") LocalIntRef potionAmplifierLevel) {
if (potionAmplifierLevel.get() > 0) {
if (Common.config.arabicNumbersForEnchantsPotions) {
return String.valueOf(this.hodgepodge$potionAmplifierLevel + 1);
return String.valueOf(potionAmplifierLevel.get() + 1);
} else {
final String translation = I18n
.format("enchantment.level." + (this.hodgepodge$potionAmplifierLevel + 1), objects);
.format("enchantment.level." + (potionAmplifierLevel.get() + 1), objects);
if (translation != null && translation.startsWith("enchantment.level.")) {
return RomanNumerals.toRomanLimited(this.hodgepodge$potionAmplifierLevel + 1, 20);
return RomanNumerals.toRomanLimited(potionAmplifierLevel.get() + 1, 20);
} else {
return translation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalIntRef;
import com.mitchej123.hodgepodge.Common;
import com.mitchej123.hodgepodge.util.RomanNumerals;

@Mixin(ItemPotion.class)
public class MixinItemPotion_FixRomanNumerals {

private int hodgepodge$potionAmplifierLevel;

@ModifyExpressionValue(
method = "addInformation",
at = @At(value = "INVOKE", target = "Lnet/minecraft/potion/PotionEffect;getAmplifier()I", ordinal = 1))
private int hodgepodge$getAmplifierLevel(int amplifier) {
this.hodgepodge$potionAmplifierLevel = amplifier;
private int hodgepodge$getAmplifierLevel(int amplifier,
@Share("potionAmplifierLevel") LocalIntRef potionAmplifierLevel) {
potionAmplifierLevel.set(amplifier);
return amplifier;
}

Expand All @@ -28,11 +29,12 @@ public class MixinItemPotion_FixRomanNumerals {
value = "INVOKE",
target = "Lnet/minecraft/util/StatCollector;translateToLocal(Ljava/lang/String;)Ljava/lang/String;",
ordinal = 1))
private String hodgepodge$addRomanNumeral(String translation) {
private String hodgepodge$addRomanNumeral(String translation,
@Share("potionAmplifierLevel") LocalIntRef potionAmplifierLevel) {
if (Common.config.arabicNumbersForEnchantsPotions) {
return String.valueOf(this.hodgepodge$potionAmplifierLevel + 1);
return String.valueOf(potionAmplifierLevel.get() + 1);
} else if (translation != null && translation.startsWith("potion.potency.")) {
return RomanNumerals.toRomanLimited(this.hodgepodge$potionAmplifierLevel + 1, 20);
return RomanNumerals.toRomanLimited(potionAmplifierLevel.get() + 1, 20);
} else {
return translation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MixinKeyBinding implements KeyBindingExt {

@Shadow
@Final
private static List keybindArray;
private static List<KeyBinding> keybindArray;
@Shadow
private int pressTime;
@Shadow
Expand Down
Loading