Skip to content

Commit

Permalink
Added handRestockListType, handRestockWhiteList, `handRestockBlac…
Browse files Browse the repository at this point in the history
…kList`
  • Loading branch information
Fallen-Breath committed Jul 15, 2021
1 parent 1d82a30 commit c4665b3
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ New tweaks:

- netherPortalSoundChance (Generic)
- disableLightUpdates (Disable)
- handRestockListType (List)
- handRestockWhiteList (List)
- handRestockBlackList (List)
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
package me.fallenbreath.tweakermore.config;

import com.google.common.collect.ImmutableList;
import fi.dy.masa.malilib.config.options.ConfigBooleanHotkeyed;
import fi.dy.masa.malilib.config.options.ConfigDouble;
import fi.dy.masa.malilib.config.options.ConfigOptionList;
import fi.dy.masa.malilib.config.options.ConfigStringList;
import fi.dy.masa.malilib.util.restrictions.ItemRestriction;
import fi.dy.masa.malilib.util.restrictions.UsageRestriction;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.util.registry.Registry;

public class TweakerMoreConfigs
{
// Generic
public static final ConfigDouble NETHER_PORTAL_SOUND_CHANCE = new ConfigDouble("netherPortalSoundChance", 0.01D, 0.0D, 0.01D, "The chance for a nether portal block to play sound\nSet it to 0.001 or 0.0001 for less noisy portal");

// List
public static final ConfigOptionList HAND_RESTORE_LIST_TYPE = new ConfigOptionList("handRestockListType", UsageRestriction.ListType.NONE, "The item restriction type for tweakHandRestock");
public static final ConfigStringList HAND_RESTORE_WHITELIST = new ConfigStringList("handRestockWhiteList", ImmutableList.of(getItemId(Items.BUCKET)), "The items that will trigger tweakHandRestock");
public static final ConfigStringList HAND_RESTORE_BLACKLIST = new ConfigStringList("handRestockBlackList", ImmutableList.of(getItemId(Items.LAVA_BUCKET)), "The items that will NOT trigger tweakHandRestock");
public static final ItemRestriction HAND_RESTORE_RESTRICTION = new ItemRestriction();

private static String getItemId(Item item)
{
return Registry.ITEM.getId(item).toString();
}

// Disable
public static final ConfigBooleanHotkeyed DISABLE_LIGHT_UPDATES = new ConfigBooleanHotkeyed("disableLightUpdates", false, "", "Yeets client-side light updates");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.fallenbreath.tweakermore.mixins.core;

import fi.dy.masa.malilib.util.restrictions.UsageRestriction;
import fi.dy.masa.tweakeroo.config.Configs;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
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.callback.CallbackInfo;

@Mixin(Configs.class)
public class ConfigsMixin
{
@Inject(method = "loadFromFile", at = @At("TAIL"), remap = false)
private static void buildRestrictionLists(CallbackInfo ci)
{

TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.setListType((UsageRestriction.ListType)TweakerMoreConfigs.HAND_RESTORE_LIST_TYPE.getOptionListValue());
TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.setListContents(TweakerMoreConfigs.HAND_RESTORE_BLACKLIST.getStrings(), TweakerMoreConfigs.HAND_RESTORE_WHITELIST.getStrings());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.collect.Lists;
import fi.dy.masa.malilib.config.IHotkeyTogglable;
import fi.dy.masa.tweakeroo.config.Configs;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
Expand All @@ -20,7 +21,7 @@ public abstract class DisableConfigsMixin
static
{
List<IHotkeyTogglable> optionList = Lists.newArrayList(OPTIONS);
optionList.add(me.fallenbreath.tweakermore.config.TweakerMoreConfigs.DISABLE_LIGHT_UPDATES);
optionList.add(TweakerMoreConfigs.DISABLE_LIGHT_UPDATES);
OPTIONS = ImmutableList.copyOf(optionList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.collect.Lists;
import fi.dy.masa.malilib.config.IConfigBase;
import fi.dy.masa.tweakeroo.config.Configs;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
Expand All @@ -20,7 +21,7 @@ public abstract class GenericConfigsMixin
static
{
List<IConfigBase> optionList = Lists.newArrayList(OPTIONS);
optionList.add(me.fallenbreath.tweakermore.config.TweakerMoreConfigs.NETHER_PORTAL_SOUND_CHANCE);
optionList.add(TweakerMoreConfigs.NETHER_PORTAL_SOUND_CHANCE);
OPTIONS = ImmutableList.copyOf(optionList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.fallenbreath.tweakermore.mixins.core;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import fi.dy.masa.malilib.config.IConfigBase;
import fi.dy.masa.tweakeroo.config.Configs;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;

import java.util.List;

@Mixin(Configs.Lists.class)
public abstract class ListsConfigsMixin
{
@Mutable
@Shadow(remap = false) @Final public static ImmutableList<IConfigBase> OPTIONS;

static
{
List<IConfigBase> optionList = Lists.newArrayList(OPTIONS);
optionList.add(TweakerMoreConfigs.HAND_RESTORE_LIST_TYPE);
optionList.add(TweakerMoreConfigs.HAND_RESTORE_BLACKLIST);
optionList.add(TweakerMoreConfigs.HAND_RESTORE_WHITELIST);
OPTIONS = ImmutableList.copyOf(optionList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package me.fallenbreath.tweakermore.mixins.handRestoreRestriction;

import fi.dy.masa.tweakeroo.config.FeatureToggle;
import fi.dy.masa.tweakeroo.util.InventoryUtils;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;

@Mixin(InventoryUtils.class)
public abstract class InventoryUtilsMixin
{

@Redirect(
method = "preRestockHand",
slice = @Slice(
from = @At(
value = "FIELD",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;",
remap = false
)
),
at = @At(
value = "INVOKE",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z",
ordinal = 0,
remap = false
),
remap = false
)
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ PlayerEntity player, Hand hand, boolean allowHotbar)
{
Item currentItem = player.getStackInHand(hand).getItem();
return featureToggle.getBooleanValue() && TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(currentItem);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package me.fallenbreath.tweakermore.mixins.handRestoreRestriction;

import fi.dy.masa.tweakeroo.config.FeatureToggle;
import fi.dy.masa.tweakeroo.tweaks.PlacementTweaks;
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;

@Mixin(PlacementTweaks.class)
public abstract class PlacementTweaksMixin
{
@Redirect(
method = "onProcessRightClickPre",
slice = @Slice(
from = @At(
value = "FIELD",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;",
remap = false
)
),
at = @At(
value = "INVOKE",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z",
ordinal = 0,
remap = false
),
remap = false
)
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ PlayerEntity player, Hand hand)
{
Item currentItem = player.getStackInHand(hand).getItem();
return featureToggle.getBooleanValue() && TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(currentItem);
}

@Redirect(
method = "cacheStackInHand",
slice = @Slice(
from = @At(
value = "FIELD",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;",
remap = false
)
),
at = @At(
value = "INVOKE",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z",
ordinal = 0,
remap = false
),
remap = false
)
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ Hand hand)
{
boolean result = featureToggle.getBooleanValue();
PlayerEntity player = MinecraftClient.getInstance().player;
if (player != null)
{
Item currentItem = player.getStackInHand(hand).getItem();
result &= TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(currentItem);
}
return result;
}

@Redirect(
method = "tryRestockHand",
slice = @Slice(
from = @At(
value = "FIELD",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;TWEAK_HAND_RESTOCK:Lfi/dy/masa/tweakeroo/config/FeatureToggle;",
remap = false
)
),
at = @At(
value = "INVOKE",
target = "Lfi/dy/masa/tweakeroo/config/FeatureToggle;getBooleanValue()Z",
ordinal = 0,
remap = false
),
remap = false
)
private static boolean applyHandRestoreRestriction(FeatureToggle featureToggle, /* parent method parameters -> */ PlayerEntity player, Hand hand, ItemStack stackOriginal)
{
return featureToggle.getBooleanValue() && TweakerMoreConfigs.HAND_RESTORE_RESTRICTION.isAllowed(stackOriginal.getItem());
}
}
4 changes: 4 additions & 0 deletions src/main/resources/tweakermore.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"package": "me.fallenbreath.tweakermore.mixins",
"compatibilityLevel": "JAVA_8",
"mixins": [
"core.ConfigsMixin",
"core.GenericConfigsMixin",
"core.ListsConfigsMixin",
"handRestoreRestriction.InventoryUtilsMixin",
"handRestoreRestriction.PlacementTweaksMixin",
"netherPortalSoundChance.NetherPortalBlockMixin"
],
"client": [
Expand Down

0 comments on commit c4665b3

Please sign in to comment.