Skip to content

Commit

Permalink
Implement Piston Block Blacklist tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jan 14, 2025
1 parent 200f811 commit 6a67578
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ All changes are toggleable via config files.
* **Overlay Message Height:** Sets the Y value of the overlay message (action bar), displayed for playing records etc.
* **Particle Limit:** Limits particles to a set amount. Should not be set too low, as it will cause particles to appear for a single tick before vanishing
* **Pickup Notification:** Displays highly configurable notifications when the player obtains or loses items
* **Piston Block Blacklist:** Integrates a blacklist of blocks which are not allowed to be pushed by pistons
* **Player Speed:** Enables the modification of base and maximum player speeds along with fixing 'Player moved too quickly' messages
* **Prevent Mob Eggs from Changing Spawners:** Prevents using Mob Spawner Eggs to change what a Spawner is spawning
* **Prevent Observer Activating on Placement:** Controls if the observer activates itself on the first tick when it is placed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import mod.acgaming.universaltweaks.tweaks.blocks.betterplacement.UTBetterPlacement;
import mod.acgaming.universaltweaks.tweaks.blocks.breakablebedrock.UTBreakableBedrock;
import mod.acgaming.universaltweaks.tweaks.blocks.dispenser.UTBlockDispenser;
import mod.acgaming.universaltweaks.tweaks.blocks.piston.UTPistonBlockBlacklist;
import mod.acgaming.universaltweaks.tweaks.entities.attributes.UTAttributes;
import mod.acgaming.universaltweaks.tweaks.items.dragonbreath.UTLeftoverDragonBreath;
import mod.acgaming.universaltweaks.tweaks.items.parry.UTParry;
Expand Down Expand Up @@ -194,6 +195,7 @@ public void postInit(FMLPostInitializationEvent event)
if (UTConfigBugfixes.ENTITIES.ENTITY_DESYNC.utEntityDesyncToggle) UTEntityDesync.initBlacklistedEntityEntries();
if (UTConfigTweaks.BLOCKS.BLOCK_DISPENSER.utBlockDispenserToggle) UTBlockDispenser.initBlockList();
if (UTConfigTweaks.BLOCKS.BREAKABLE_BEDROCK.utBreakableBedrockToggle) UTBreakableBedrock.initToolList();
if (UTConfigTweaks.BLOCKS.PISTON.utPistonBlockBlacklistToggle) UTPistonBlockBlacklist.initBlockBlacklist();
if (UTConfigTweaks.MISC.SWING_THROUGH_GRASS.utSwingThroughGrassToggle) UTSwingThroughGrassLists.initLists();
if (UTConfigTweaks.MISC.INCURABLE_POTIONS.utIncurablePotionsToggle) UTIncurablePotions.initPotionList();
if (UTConfigTweaks.ITEMS.utLeftoverBreathBottleToggle) UTLeftoverDragonBreath.postInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.core.UTLoadingPlugin;
import mod.acgaming.universaltweaks.tweaks.blocks.breakablebedrock.UTBreakableBedrock;
import mod.acgaming.universaltweaks.tweaks.blocks.piston.UTPistonBlockBlacklist;
import mod.acgaming.universaltweaks.tweaks.items.parry.UTParry;
import mod.acgaming.universaltweaks.tweaks.items.rarity.UTCustomRarity;
import mod.acgaming.universaltweaks.tweaks.items.useduration.UTCustomUseDuration;
Expand Down Expand Up @@ -116,6 +117,10 @@ public static class BlocksCategory
@Config.Name("Overhaul Beacon")
public final OverhaulBeaconCategory OVERHAUL_BEACON = new OverhaulBeaconCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.blocks.piston")
@Config.Name("Piston")
public final PistonCategory PISTON = new PistonCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.blocks.sapling")
@Config.Name("Sapling Behavior")
public final SaplingBehaviorCategory SAPLING_BEHAVIOR = new SaplingBehaviorCategory();
Expand Down Expand Up @@ -367,6 +372,22 @@ public OverhaulBeaconCategory()
}
}

public static class PistonCategory
{
@Config.RequiresMcRestart
@Config.Name("[1] Piston Block Blacklist Toggle")
@Config.Comment("Integrates a blacklist of blocks which are not allowed to be pushed by pistons")
public boolean utPistonBlockBlacklistToggle = false;

@Config.Name("[2] Piston Block Blacklist")
@Config.Comment
({
"Blacklist of blocks which are not allowed to be pushed by pistons",
"Syntax: modid:block"
})
public String[] utPistonBlockBlacklist = new String[] {};
}

public static class SaplingBehaviorCategory
{
@Config.RequiresMcRestart
Expand Down Expand Up @@ -2473,6 +2494,7 @@ public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event
{
ConfigManager.sync(UniversalTweaks.MODID, Config.Type.INSTANCE);
if (BLOCKS.BREAKABLE_BEDROCK.utBreakableBedrockToggle) UTBreakableBedrock.initToolList();
if (BLOCKS.PISTON.utPistonBlockBlacklistToggle) UTPistonBlockBlacklist.initBlockBlacklist();
if (MISC.ARMOR_CURVE.utArmorCurveToggle) UTArmorCurve.initExpressions();
if (MISC.SWING_THROUGH_GRASS.utSwingThroughGrassToggle) UTSwingThroughGrassLists.initLists();
if (MISC.INCURABLE_POTIONS.utIncurablePotionsToggle) UTIncurablePotions.initPotionList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.blocks.lenientpaths.json", () -> UTConfigTweaks.BLOCKS.utLenientPathsToggle);
put("mixins.tweaks.blocks.observer.json", () -> UTConfigTweaks.BLOCKS.utPreventObserverActivatesOnPlacement);
put("mixins.tweaks.blocks.overhaulbeacon.json", () -> UTConfigTweaks.BLOCKS.OVERHAUL_BEACON.utOverhaulBeaconToggle);
put("mixins.tweaks.blocks.piston.json", () -> UTConfigTweaks.BLOCKS.PISTON.utPistonBlockBlacklistToggle);
put("mixins.tweaks.blocks.pumpkinplacing.json", () -> UTConfigTweaks.BLOCKS.utUnsupportedPumpkinPlacing);
put("mixins.tweaks.blocks.sapling.json", () -> UTConfigTweaks.BLOCKS.SAPLING_BEHAVIOR.utSaplingBehaviorToggle);
put("mixins.tweaks.blocks.witherstructure.json", () -> UTConfigTweaks.ENTITIES.utWitherPlacement);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mod.acgaming.universaltweaks.tweaks.blocks.piston;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.ForgeRegistries;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;

public class UTPistonBlockBlacklist
{
public static final List<Block> BLOCK_BLACKLIST = new ArrayList<>();

public static void initBlockBlacklist()
{
BLOCK_BLACKLIST.clear();
try
{
for (String string : UTConfigTweaks.BLOCKS.PISTON.utPistonBlockBlacklist)
{
ResourceLocation resLoc = new ResourceLocation(string);
if (ForgeRegistries.BLOCKS.containsKey(resLoc)) BLOCK_BLACKLIST.add(ForgeRegistries.BLOCKS.getValue(resLoc));
}
}
catch (Exception e)
{
e.printStackTrace();
}
UniversalTweaks.LOGGER.info("Piston block blacklist initialized");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mod.acgaming.universaltweaks.tweaks.blocks.piston.mixin;

import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigGeneral;
import mod.acgaming.universaltweaks.tweaks.blocks.piston.UTPistonBlockBlacklist;
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.CallbackInfoReturnable;

@Mixin(BlockPistonBase.class)
public abstract class UTPistonBlockBlacklistMixin
{
@Inject(method = "canPush", at = @At("HEAD"), cancellable = true)
private static void utPistonCanPush(IBlockState blockState, World world, BlockPos pos, EnumFacing facing, boolean destroyBlocks, EnumFacing enumFacing, CallbackInfoReturnable<Boolean> cir)
{
if (UTConfigGeneral.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTPistonBlockBlacklist ::: Can push block check");
if (UTPistonBlockBlacklist.BLOCK_BLACKLIST.contains(blockState.getBlock())) cir.setReturnValue(false);
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ cfg.universaltweaks.tweaks.blocks.breakablebedrock=Breakable Bedrock
cfg.universaltweaks.tweaks.blocks.finitewater=Finite Water
cfg.universaltweaks.tweaks.blocks.miningglitch=Mining Glitch
cfg.universaltweaks.tweaks.blocks.overhaulbeacon=Overhaul Beacon
cfg.universaltweaks.tweaks.blocks.piston=Piston
cfg.universaltweaks.tweaks.blocks.sapling=Sapling Behavior
cfg.universaltweaks.tweaks.entities.attributes=Attributes
cfg.universaltweaks.tweaks.entities.betterburning=Better Burning
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/mixins.tweaks.blocks.piston.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.tweaks.blocks.piston.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTPistonBlockBlacklistMixin"]
}

0 comments on commit 6a67578

Please sign in to comment.