-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show Renamed AE2 Parts and Blocks in TOP
- Loading branch information
1 parent
d6d7ebe
commit 5f27b9d
Showing
5 changed files
with
216 additions
and
1 deletion.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/com/nomiceu/nomilabs/integration/top/AECustomNameOverride.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.nomiceu.nomilabs.integration.top; | ||
|
||
import static mcjty.theoneprobe.api.TextStyleClass.MODNAME; | ||
|
||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.world.World; | ||
|
||
import appeng.helpers.ICustomNameObject; | ||
import appeng.integration.modules.theoneprobe.part.PartAccessor; | ||
import appeng.tile.AEBaseTile; | ||
import mcjty.theoneprobe.Tools; | ||
import mcjty.theoneprobe.api.*; | ||
import mcjty.theoneprobe.config.Config; | ||
|
||
public class AECustomNameOverride implements IBlockDisplayOverride { | ||
|
||
private static final PartAccessor accessor = new PartAccessor(); | ||
|
||
@Override | ||
public boolean overrideStandardInfo(ProbeMode mode, IProbeInfo info, EntityPlayer player, World world, | ||
IBlockState state, IProbeHitData data) { | ||
var tile = world.getTileEntity(data.getPos()); | ||
var part = accessor.getMaybePart(tile, data); | ||
|
||
String customName = null; | ||
|
||
// noinspection SimplifyOptionalCallChains | ||
if (!(tile instanceof AEBaseTile) && !part.isPresent()) return false; | ||
|
||
if (part.isPresent()) { | ||
if (part.get() instanceof ICustomNameObject nameObj) { | ||
if (nameObj.hasCustomInventoryName()) | ||
customName = nameObj.getCustomInventoryName(); | ||
} | ||
} else if (tile instanceof AEBaseTile base) { | ||
if (base.hasCustomInventoryName()) | ||
customName = base.getCustomInventoryName(); | ||
} | ||
|
||
if (customName == null) return false; | ||
|
||
customName = customName.trim(); | ||
if (customName.isEmpty()) return false; | ||
|
||
ItemStack pickBlock = data.getPickBlock(); | ||
IElement customNameElement = new CustomNameElement(pickBlock, customName); | ||
|
||
if (Tools.show(mode, Config.getRealConfig().getShowModName())) | ||
info.horizontal() | ||
.item(pickBlock) | ||
.vertical() | ||
.element(customNameElement) | ||
.text(MODNAME + Tools.getModName(state.getBlock())); | ||
else | ||
info.horizontal(info.defaultLayoutStyle() | ||
.alignment(ElementAlignment.ALIGN_CENTER)) | ||
.item(pickBlock) | ||
.element(customNameElement); | ||
|
||
return true; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/com/nomiceu/nomilabs/integration/top/CustomNameElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.nomiceu.nomilabs.integration.top; | ||
|
||
import static mcjty.theoneprobe.apiimpl.elements.ElementVertical.SPACING; | ||
import static net.minecraft.util.text.TextFormatting.ITALIC; | ||
import static net.minecraft.util.text.TextFormatting.RESET; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import mcjty.theoneprobe.api.IElement; | ||
import mcjty.theoneprobe.apiimpl.client.ElementTextRender; | ||
import mcjty.theoneprobe.network.NetworkTools; | ||
|
||
/** | ||
* An element that displays the normal ItemStack display name, | ||
* and a custom name only IF it is not the same as the ItemStack display name. | ||
*/ | ||
public class CustomNameElement implements IElement { | ||
|
||
public static final int TEXT_HEIGHT = 10; | ||
|
||
private final ItemStack pickStack; | ||
private final String customName; | ||
|
||
public CustomNameElement(ItemStack pickStack, String customName) { | ||
this.pickStack = pickStack; | ||
this.customName = customName; | ||
} | ||
|
||
public CustomNameElement(ByteBuf buf) { | ||
if (buf.readBoolean()) { | ||
pickStack = NetworkTools.readItemStack(buf); | ||
} else { | ||
pickStack = ItemStack.EMPTY; | ||
} | ||
|
||
customName = NetworkTools.readStringUTF8(buf); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void render(int x, int y) { | ||
if (!pickStack.isEmpty()) | ||
ElementTextRender.render(pickStack.getDisplayName(), x, y); | ||
if (shouldRender()) | ||
ElementTextRender.render(ITALIC + "(" + customName + ")" + RESET, x, y + TEXT_HEIGHT + SPACING); | ||
} | ||
|
||
@Override | ||
public int getWidth() { | ||
var pickStackWidth = pickStack.isEmpty() ? TEXT_HEIGHT : ElementTextRender.getWidth(pickStack.getDisplayName()); | ||
|
||
return shouldRender() ? Math.max(pickStackWidth, ElementTextRender.getWidth(customName)) : pickStackWidth; | ||
} | ||
|
||
@Override | ||
public int getHeight() { | ||
return shouldRender() ? TEXT_HEIGHT * 2 + SPACING : TEXT_HEIGHT; | ||
} | ||
|
||
@Override | ||
public void toBytes(ByteBuf buf) { | ||
if (!pickStack.isEmpty()) { | ||
buf.writeBoolean(true); | ||
NetworkTools.writeItemStack(buf, pickStack); | ||
} else { | ||
buf.writeBoolean(false); | ||
} | ||
|
||
NetworkTools.writeStringUTF8(buf, customName); | ||
} | ||
|
||
@Override | ||
public int getID() { | ||
return LabsTOPManager.CUSTOM_NAME_ELEMENT; | ||
} | ||
|
||
private boolean shouldRender() { | ||
if (pickStack.isEmpty()) return true; | ||
|
||
return !pickStack.getDisplayName().trim().equals(customName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/nomiceu/nomilabs/mixin/ae2/AEBaseTileBlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.nomiceu.nomilabs.mixin.ae2; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.RayTraceResult; | ||
import net.minecraft.world.IBlockAccess; | ||
import net.minecraft.world.World; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import appeng.block.AEBaseBlock; | ||
import appeng.block.AEBaseTileBlock; | ||
import appeng.tile.AEBaseTile; | ||
import appeng.util.SettingsFrom; | ||
|
||
@Mixin(value = AEBaseTileBlock.class, remap = false) | ||
public abstract class AEBaseTileBlockMixin extends AEBaseBlock { | ||
|
||
@Shadow | ||
@Nullable | ||
public abstract <T extends AEBaseTile> T getTileEntity(IBlockAccess w, BlockPos pos); | ||
|
||
/** | ||
* Default Ignored Constructor | ||
*/ | ||
private AEBaseTileBlockMixin(Material mat) { | ||
super(mat); | ||
} | ||
|
||
@Override | ||
@Unique | ||
@NotNull | ||
public ItemStack getPickBlock(@NotNull IBlockState state, @NotNull RayTraceResult target, @NotNull World world, | ||
@NotNull BlockPos pos, @NotNull EntityPlayer player) { | ||
ItemStack baseStack = super.getPickBlock(state, target, world, pos, player); | ||
|
||
AEBaseTile tile = getTileEntity(world, pos); | ||
if (tile == null) return baseStack; | ||
|
||
NBTTagCompound tag = tile.downloadSettings(SettingsFrom.DISMANTLE_ITEM); | ||
baseStack.setTagCompound(tag); | ||
return baseStack; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters