Skip to content

Commit

Permalink
Properly Fix FTB Utils Related Crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 24, 2025
1 parent 8d7decb commit b27e4a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void sendMessage(EntityPlayerMP player) {
/**
* Reflection to see whether a chunk is editable by the player.
* Equal to `getChunk(new ChunkDimPos(posX, posZ, dim)).getTeam().hasStatus(instance.universe.getPlayer(player),
* chunk.getData().getAttackEntitiesStatus())`
* chunk.getData().getEditBlocksStatus())`
*/
private static boolean playerCanEdit(int posX, int posZ, int dim, EntityPlayerMP player) {
var chunk = getChunk(posX, posZ, dim);
Expand Down Expand Up @@ -155,7 +155,6 @@ private static ClaimedChunk getChunk(int posX, int posZ, int dim) {
var claimedChunksClass = Class.forName("com.feed_the_beast.ftbutilities.data.ClaimedChunks");
var getChunkMethod = claimedChunksClass.getDeclaredMethod("getChunk", chunkDimPosClass);

// noinspection JavaReflectionInvocation
return (ClaimedChunk) getChunkMethod.invoke(instance, chunkDimPosClass.cast(obj));
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException |
InstantiationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class FTBUtilitiesPlayerEventHandlerMixin {

@Unique
private static boolean cancelledMainHandPlace = false;
private static boolean labs$cancelledMainHand = false;

/* New Logic */

Expand All @@ -34,13 +34,14 @@ public class FTBUtilitiesPlayerEventHandlerMixin {
private static void handleAndCancelPlace(PlayerInteractEvent.RightClickBlock event, CallbackInfo ci) {
var stack = event.getEntityPlayer().getHeldItem(event.getHand());
var item = stack.getItem();
var world = event.getWorld();
var pos = event.getPos();

if (event.getHand() == EnumHand.MAIN_HAND)
cancelledMainHandPlace = false;
labs$cancelledMainHand = false;
// Off Hand is always called after main hand
else if (event.getHand() == EnumHand.OFF_HAND && cancelledMainHandPlace) {
cancelledMainHandPlace = false;
else if (event.getHand() == EnumHand.OFF_HAND && labs$cancelledMainHand) {
labs$cancelledMainHand = false;
event.setCanceled(true);
ci.cancel();
return;
Expand All @@ -50,15 +51,15 @@ else if (event.getHand() == EnumHand.OFF_HAND && cancelledMainHandPlace) {
return;

// Offset Pos if Needed
if (event.getFace() != null && !itemBlock.getBlock().isReplaceable(event.getWorld(), pos))
if (event.getFace() != null && !world.getBlockState(pos).getBlock().isReplaceable(world, pos))
pos = pos.offset(event.getFace());

if (!CanEditChunkHelper.cannotEditChunk(event.getEntityPlayer(),
pos, itemBlock.getBlock().getStateFromMeta(stack.getMetadata())))
return;

event.setCanceled(true);
cancelledMainHandPlace = true;
labs$cancelledMainHand = true;

if (!event.getWorld().isRemote)
DisplayGameOverlayMessageHelper.sendMessageOrDisplay(event.getEntityPlayer(),
Expand Down

0 comments on commit b27e4a0

Please sign in to comment.