Skip to content

Commit

Permalink
Merge pull request #476 from jchung01/vanilla-tweaks
Browse files Browse the repository at this point in the history
Fix block interactions with Better Placement tweak
  • Loading branch information
ACGaming authored May 23, 2024
2 parents 5382ddc + 2d9616f commit 5eb330f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.bugfixes.misc.spectatormenu.json", () -> UTConfigBugfixes.MISC.utSpectatorMenuToggle);
put("mixins.bugfixes.misc.startup.json", () -> UTConfigTweaks.PERFORMANCE.utFasterBackgroundStartupToggle);
put("mixins.bugfixes.world.frustumculling.json", () -> UTConfigBugfixes.WORLD.utFrustumCullingToggle);
put("mixins.tweaks.blocks.betterplacement.json", () -> UTConfigTweaks.BLOCKS.BETTER_PLACEMENT.utBetterPlacementToggle);
put("mixins.tweaks.entities.autojump.json", () -> UTConfigTweaks.ENTITIES.utAutoJumpToggle);
put("mixins.tweaks.entities.burning.player.json", () -> UTConfigTweaks.ENTITIES.utFirstPersonBurningOverlay != -0.3D);
put("mixins.tweaks.items.attackcooldown.client.json", () -> UTConfigTweaks.ITEMS.ATTACK_COOLDOWN.utAttackCooldownToggle);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mod.acgaming.universaltweaks.tweaks.blocks.betterplacement;

public interface IInteractable
{
boolean isInteractable();
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package mod.acgaming.universaltweaks.tweaks.blocks.betterplacement;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.RayTraceResult.Type;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;

// Courtesy of tterrag1098, BucketOfCompasses
public class UTBetterPlacement
{
Expand Down Expand Up @@ -47,7 +45,7 @@ public static void utBetterPlacement(TickEvent.ClientTickEvent event)
{
Minecraft.getMinecraft().rightClickDelayTimer = 0;
}
else if (UTConfigTweaks.BLOCKS.BETTER_PLACEMENT.utBetterPlacementNewLoc && pos.equals(lastTargetPos) && side == lastTargetSide && !isDrawer(pos))
else if (UTConfigTweaks.BLOCKS.BETTER_PLACEMENT.utBetterPlacementNewLoc && pos.equals(lastTargetPos) && side == lastTargetSide && !isInteractableAt(pos))
{
Minecraft.getMinecraft().rightClickDelayTimer = 4;
}
Expand All @@ -59,15 +57,8 @@ else if (UTConfigTweaks.BLOCKS.BETTER_PLACEMENT.utBetterPlacementNewLoc && pos.e
}
}

public static boolean isDrawer(BlockPos pos)
private static boolean isInteractableAt(BlockPos pos)
{
try
{
return Loader.isModLoaded("storagedrawers") && Minecraft.getMinecraft().world.getBlockState(pos).getBlock().getRegistryName().getNamespace().equals("storagedrawers");
}
catch (Exception e)
{
return false;
}
return ((IInteractable) Minecraft.getMinecraft().world.getBlockState(pos).getBlock()).isInteractable();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package mod.acgaming.universaltweaks.tweaks.blocks.betterplacement.mixin;

import mod.acgaming.universaltweaks.tweaks.blocks.betterplacement.IInteractable;
import net.minecraft.block.Block;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = Block.class)
public class UTInteractableBlockMixin implements IInteractable
{
@Unique
private boolean ut$interactable = true;

@Override
public boolean isInteractable()
{
return ut$interactable;
}

/**
* @reason Block is assumed NOT interactable if the default/super implementation is called.
*/
@Inject(method = "onBlockActivated", at = @At(value = "HEAD"))
private void utSetInteractable(CallbackInfoReturnable<Boolean> cir)
{
ut$interactable = false;
}
}
7 changes: 7 additions & 0 deletions src/main/resources/mixins.tweaks.blocks.betterplacement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.tweaks.blocks.betterplacement.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"client": ["UTInteractableBlockMixin"]
}

0 comments on commit 5eb330f

Please sign in to comment.