Skip to content

Commit

Permalink
Merge branch '1.19.2' into 1.18.2
Browse files Browse the repository at this point in the history
Backport 1.2.2
  • Loading branch information
Hidoni committed May 4, 2023
2 parents ac3fe0a + 3504139 commit f15a9f2
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.2.2+1.18.2 - 05/05/2023
- Add config option to disable transmogs during PvP for set duration

# 1.2.1+1.18.2 - 28/04/2023
- Significant Performance Optimizations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"block.transmog.transmogrification_table": "Transmogrification Table",
"item.transmog.void_fragment": "Void Fragment",
"itemGroup.transmog.creative_tab": "Transmog",
"transmog.config.disable_during_pvp_duration": "Disable During PvP",
"transmog.config.disable_during_pvp_duration.label": "%d Seconds",
"transmog.config.disable_during_pvp_duration.tooltip": "Temporarily disable rendering transmogs for a set amount of time if you hit another player. Set to 0 to ignore PvP.",
"transmog.config.render": "Render Transmogs",
"transmog.config.render.everywhere": "In World & Inventory",
"transmog.config.render.everywhere.tooltip": "Render transmogs in world, inventories and the hotbar. Items will look like the item they're transmogrified as even in your inventory (Hidden items will still show up as the original item in the inventory). This might get confusing!",
Expand Down
36 changes: 33 additions & 3 deletions Common/src/main/java/com/hidoni/transmog/TransmogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,39 @@
import net.minecraft.world.item.ItemStack;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class TransmogUtils {
private static boolean notInPvP = true;
private static Thread pvpTimerThread = null;

public static void startPvP() {
if (Config.pvpDisableDuration > 0) {
setNotInPvP(false);
if (pvpTimerThread != null) {
Constants.LOG.info("Client player still involved in PvP, Extending transmog disable for another {} seconds", Config.pvpDisableDuration);
Constants.LOG.debug("Interrupting existing PvP timer thread: {}", pvpTimerThread);
pvpTimerThread.interrupt();
} else {
Constants.LOG.info("Client player involved in PvP, Disabling transmogs for {} seconds", Config.pvpDisableDuration);
}
pvpTimerThread = new Thread(() -> {
try {
TimeUnit.SECONDS.sleep(Config.pvpDisableDuration);
setNotInPvP(true);
Constants.LOG.info("PvP Timer finished, Transmog re-enabled.");
} catch (InterruptedException ignored) {
}
});
pvpTimerThread.start();
Constants.LOG.debug("Created new PvP timer thread: {}", pvpTimerThread);
}
}

private static synchronized void setNotInPvP(boolean notInPvP) {
TransmogUtils.notInPvP = notInPvP;
}

public static boolean isItemStackTransmogged(ItemStack itemStack) {
return itemStack.getTagElement(Constants.TRANSMOG_ITEM_TAG) != null;
}
Expand Down Expand Up @@ -36,11 +67,10 @@ public static ItemStack getAppearanceItemStack(ItemStack itemStack, boolean keep
}

public static ItemStack getAppearanceStackOrOriginal(ItemStack itemStack) {
if (Config.renderOption.renderInWorld && isItemStackTransmogged(itemStack)) {
if (notInPvP && Config.renderOption.renderInWorld && isItemStackTransmogged(itemStack)) {
if (!RenderUtils.INSTANCE.isCalledForInventory()) {
return getAppearanceItemStack(itemStack, false);
}
else if (Config.renderOption.renderInInventory) {
} else if (Config.renderOption.renderInInventory) {
ItemStack appearanceItemStack = getAppearanceItemStack(itemStack, true);
if (isHiddenItem(appearanceItemStack)) {
return itemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public class Config {
public static TransmogRenderOption renderOption = TransmogRenderOption.IN_WORLD;
public static TooltipDetailLevel tooltipDetailLevel = TooltipDetailLevel.FULL;
public static int pvpDisableDuration = 0;
@SuppressWarnings("UnnecessaryModifier")
private transient static final Gson GSON = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).serializeNulls().serializeSpecialFloatingPointValues().setPrettyPrinting().setLenient().create();

Expand Down
12 changes: 12 additions & 0 deletions Common/src/main/java/com/hidoni/transmog/gui/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.ChatFormatting;
import net.minecraft.client.CycleOption;
import net.minecraft.client.Minecraft;
import net.minecraft.client.ProgressOption;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.OptionsList;
import net.minecraft.client.gui.screens.OptionsSubScreen;
Expand Down Expand Up @@ -71,10 +72,21 @@ private void addConfigOptionsToList() {
(options) -> Config.tooltipDetailLevel,
(options, option, value) -> Config.tooltipDetailLevel = value
);
ProgressOption pvpDurationProgressOption = new ProgressOption(
TranslationKeys.TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_OPTION,
0D,
120D,
1F,
(options) -> (double) Config.pvpDisableDuration,
(options, value) -> Config.pvpDisableDuration = (int)Math.round(value),
(options, progressOption) -> new TranslatableComponent("options.generic_value", new TranslatableComponent(TranslationKeys.TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_OPTION), Config.pvpDisableDuration == 0 ? new TranslatableComponent(TranslationKeys.TRANSMOG_CONFIG_RENDER_OPTION_OFF) : new TranslatableComponent(TranslationKeys.TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_VALUE_LABEL, Config.pvpDisableDuration)),
(mc) -> mc.font.split(new TranslatableComponent(TranslationKeys.TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_TOOLTIP), 200)
);
transmogRenderOptionCycleOption.setTooltip((mc) -> (option) -> mc.font.split(new TranslatableComponent(option.getTooltipKey()), 200));
tooltipDetailLevelCycleOption.setTooltip((mc) -> (option) -> mc.font.split(new TranslatableComponent(option.getTooltipKey()), 200));
this.list.addBig(transmogRenderOptionCycleOption);
this.list.addBig(tooltipDetailLevelCycleOption);
this.list.addBig(pvpDurationProgressOption);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public class TranslationKeys {
public static final String TRANSMOG_CONFIG_TOOLTIP_OPTION_MINIMAL_CAPTION = "transmog.config.tooltip.minimal.tooltip";
public static final String TRANSMOG_CONFIG_TOOLTIP_OPTION_FULL = "transmog.config.tooltip.full";
public static final String TRANSMOG_CONFIG_TOOLTIP_OPTION_FULL_CAPTION = "transmog.config.tooltip.full.tooltip";
public static final String TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_OPTION = "transmog.config.disable_during_pvp_duration";
public static final String TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_TOOLTIP = "transmog.config.disable_during_pvp_duration.tooltip";
public static final String TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_VALUE_LABEL = "transmog.config.disable_during_pvp_duration.label";
}
24 changes: 22 additions & 2 deletions Common/src/main/java/com/hidoni/transmog/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,41 @@

import com.hidoni.transmog.RenderUtils;
import com.hidoni.transmog.TransmogUtils;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Player.class)
public class PlayerMixin {
@Inject(method = "getItemBySlot", at=@At("RETURN"), cancellable = true)
public abstract class PlayerMixin extends LivingEntity {
@Shadow
public abstract boolean isLocalPlayer();

protected PlayerMixin(EntityType<? extends LivingEntity> type, Level level) {
super(type, level);
}

@Inject(method = "getItemBySlot", at = @At("RETURN"), cancellable = true)
private void transmogItemBySlot(EquipmentSlot slot, CallbackInfoReturnable<ItemStack> cir) {
ItemStack returnValue = cir.getReturnValue();
if (TransmogUtils.isItemStackTransmogged(returnValue) && RenderUtils.INSTANCE.isCalledForRendering()) {
cir.setReturnValue(TransmogUtils.getAppearanceStackOrOriginal(returnValue));
}
}

@Inject(method = "attack", at = @At("HEAD"))
private void attack(Entity target, CallbackInfo ci) {
if (this.isLocalPlayer() && target instanceof Player) {
TransmogUtils.startPvP();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ protected void addTranslations() {
add(TranslationKeys.TRANSMOG_CONFIG_TOOLTIP_OPTION_MINIMAL_CAPTION, "Add the name of the appearance item that an item is transmogrified into to its tooltip.");
add(TranslationKeys.TRANSMOG_CONFIG_TOOLTIP_OPTION_FULL, "Full");
add(TranslationKeys.TRANSMOG_CONFIG_TOOLTIP_OPTION_FULL_CAPTION, "Add the original tooltip of the appearance item that an item is transmogrified into to its tooltip. This is the default option.");
add(TranslationKeys.TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_OPTION, "Disable During PvP");
add(TranslationKeys.TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_TOOLTIP, "Temporarily disable rendering transmogs for a set amount of time if you hit another player. Set to 0 to ignore PvP.");
add(TranslationKeys.TRANSMOG_CONFIG_DISABLE_DURING_PVP_DURATION_VALUE_LABEL, "%d Seconds");
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project
mod_version=1.2.1
mod_version=1.2.2
archives_base_name=transmog
group=com.hidoni.transmog

Expand Down

0 comments on commit f15a9f2

Please sign in to comment.