This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from EpimorphicPioneers/color
添加已染色方块的显示
- Loading branch information
Showing
9 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
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
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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/epimorphismmc/monazite/integration/jade/provider/StainedColorProvider.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,50 @@ | ||
package com.epimorphismmc.monazite.integration.jade.provider; | ||
|
||
import com.epimorphismmc.monazite.Monazite; | ||
import com.gregtechceu.gtceu.api.blockentity.PipeBlockEntity; | ||
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; | ||
import com.gregtechceu.gtceu.api.machine.MetaMachine; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.Style; | ||
import net.minecraft.resources.ResourceLocation; | ||
import snownee.jade.api.BlockAccessor; | ||
import snownee.jade.api.IBlockComponentProvider; | ||
import snownee.jade.api.IServerDataProvider; | ||
import snownee.jade.api.ITooltip; | ||
import snownee.jade.api.config.IPluginConfig; | ||
|
||
import java.util.Locale; | ||
|
||
public enum StainedColorProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> { | ||
INSTANCE; | ||
|
||
@Override | ||
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) { | ||
if (blockAccessor.getServerData().contains("StainedColor")) { | ||
int paintingColor = blockAccessor.getServerData().getInt("StainedColor"); | ||
if (paintingColor != -1) { | ||
iTooltip.add(Component.translatable("monazite.stained", "#" + Integer.toHexString(paintingColor).toUpperCase(Locale.ROOT)).withStyle(Style.EMPTY.withColor(paintingColor))); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccessor) { | ||
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) { | ||
MetaMachine metaMachine = blockEntity.getMetaMachine(); | ||
if (metaMachine != null) { | ||
int paintingColor = metaMachine.getPaintingColor(); | ||
compoundTag.putInt("StainedColor", paintingColor); | ||
} | ||
} else if (blockAccessor.getBlockEntity() instanceof PipeBlockEntity<?, ?> pipe) { | ||
int paintingColor = pipe.getPaintingColor(); | ||
compoundTag.putInt("StainedColor", paintingColor); | ||
} | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return Monazite.id("stained_color"); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/epimorphismmc/monazite/integration/top/provider/StainedColorProvider.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,40 @@ | ||
package com.epimorphismmc.monazite.integration.top.provider; | ||
|
||
import com.epimorphismmc.monazite.Monazite; | ||
import com.gregtechceu.gtceu.api.blockentity.PipeBlockEntity; | ||
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; | ||
import mcjty.theoneprobe.api.ElementAlignment; | ||
import mcjty.theoneprobe.api.IProbeHitData; | ||
import mcjty.theoneprobe.api.IProbeInfo; | ||
import mcjty.theoneprobe.api.IProbeInfoProvider; | ||
import mcjty.theoneprobe.api.ProbeMode; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
import java.util.Locale; | ||
|
||
public class StainedColorProvider implements IProbeInfoProvider { | ||
@Override | ||
public ResourceLocation getID() { | ||
return Monazite.id("stained_color"); | ||
} | ||
|
||
@Override | ||
public void addProbeInfo(ProbeMode probeMode, IProbeInfo iProbeInfo, Player player, Level level, BlockState blockState, IProbeHitData iProbeHitData) { | ||
BlockEntity blockEntity = level.getBlockEntity(iProbeHitData.getPos()); | ||
int paintingColor = -1; | ||
if (blockEntity instanceof IMachineBlockEntity machineBlockEntity) { | ||
paintingColor = machineBlockEntity.getMetaMachine().getPaintingColor(); | ||
} else if (blockEntity instanceof PipeBlockEntity<?, ?> pipe) { | ||
paintingColor = pipe.getPaintingColor(); | ||
} | ||
if (paintingColor != -1) { | ||
IProbeInfo horizontal = iProbeInfo.horizontal(iProbeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)); | ||
horizontal.mcText(Component.translatable("monazite.stained", "#" + Integer.toHexString(paintingColor).toUpperCase(Locale.ROOT))); | ||
} | ||
} | ||
} |