Skip to content

Commit

Permalink
Make Phantomface HUD Valid Check Server-Side
Browse files Browse the repository at this point in the history
Fixes issues with capabilities not being detected for specific blocks. So far the only block found with this issue is ME Storage Exposers from NAE2.
  • Loading branch information
IntegerLimit committed Feb 6, 2025
1 parent 048c9e7 commit 86c00b9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.nomiceu.nomilabs.integration.actuallyadditions;

public interface AccessibleTileEntityPhantomface {

boolean labs$boundValid();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.nomiceu.nomilabs.integration.actuallyadditions.AccessibleTileEntityPhantomface;

import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
import gregtech.api.metatileentity.MetaTileEntity;
Expand Down Expand Up @@ -57,7 +59,8 @@ private void betterHudDisplaying(Minecraft mc, EntityPlayer player, ItemStack st
return;
}

if (phantom.isBoundThingInRange()) {
if (((phantom instanceof AccessibleTileEntityPhantomface access) && access.labs$boundValid()) ||
phantom.isBoundThingInRange()) {
y = labs$draw(font, increaseBy, x, y, "aa.gui.hover.phantom.connected");
} else {
y = labs$draw(font, increaseBy, x, y, "aa.gui.hover.phantom.connected_failed");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.nomiceu.nomilabs.mixin.actuallyadditions;

import net.minecraft.nbt.NBTTagCompound;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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.CallbackInfo;

import com.nomiceu.nomilabs.integration.actuallyadditions.AccessibleTileEntityPhantomface;

import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomface;

/**
* Checks whether bound target is valid server-side, so that tile entities with custom capabilities
* (e.g. NAE2's Storage Exposer) shows correctly in HUD.
*/
@Mixin(value = TileEntityPhantomface.class, remap = false)
public abstract class TileEntityPhantomfaceMixin implements AccessibleTileEntityPhantomface {

@Shadow
public abstract boolean isBoundThingInRange();

@Unique
private boolean labs$boundValid = false;

@Unique
@Override
public boolean labs$boundValid() {
return labs$boundValid;
}

@Inject(method = "writeSyncableNBT", at = @At("TAIL"))
private void writeBoundValid(NBTTagCompound compound, TileEntityBase.NBTType type, CallbackInfo ci) {
labs$boundValid = isBoundThingInRange();
if (type != TileEntityBase.NBTType.SAVE_BLOCK)
compound.setBoolean("labs$boundValid", labs$boundValid);
}

@Inject(method = "readSyncableNBT", at = @At("TAIL"))
private void readBoundValid(NBTTagCompound compound, TileEntityBase.NBTType type, CallbackInfo ci) {
if (type != TileEntityBase.NBTType.SAVE_BLOCK)
labs$boundValid = compound.getBoolean("labs$boundValid");
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.nomilabs.actuallyadditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"mixins": [
"BlockLaserRelayMixin",
"ItemPhantomConnectorMixin",
"TileEntityPhantomfaceMixin",
"TileEntityXPSolidifierMixin"
],
"client": [
Expand Down

0 comments on commit 86c00b9

Please sign in to comment.