-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.20.1' into 1.20.1
- Loading branch information
Showing
9 changed files
with
298 additions
and
11 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
12 changes: 12 additions & 0 deletions
12
src/api/java/dev/compactmods/machines/api/core/JadeInfo.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,12 @@ | ||
package dev.compactmods.machines.api.core; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class JadeInfo { | ||
public static final String JADE_CONFIG = "config.jade.plugin_compactmachines"; | ||
|
||
public static final String MACHINE = JADE_CONFIG.concat(".machine"); | ||
public static final String MACHINE_TUNNELS = JADE_CONFIG.concat(".machine_tunnels"); | ||
public static final String TUNNEL = JADE_CONFIG.concat(".tunnel"); | ||
public static final String TUNNEL_CONNECTION = JADE_CONFIG.concat(".tunnel_connection"); | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/dev/compactmods/machines/compat/jade/JadePlugin.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,29 @@ | ||
package dev.compactmods.machines.compat.jade; | ||
|
||
import dev.compactmods.machines.compat.jade.providers.client.CompactMachineProvider; | ||
import dev.compactmods.machines.compat.jade.providers.client.TunnelProvider; | ||
import dev.compactmods.machines.compat.jade.providers.server.CompactMachineComponentProvider; | ||
import dev.compactmods.machines.compat.jade.providers.server.TunnelComponentProvider; | ||
import dev.compactmods.machines.machine.CompactMachineBlock; | ||
import dev.compactmods.machines.machine.CompactMachineBlockEntity; | ||
import dev.compactmods.machines.tunnel.TunnelWallBlock; | ||
import dev.compactmods.machines.tunnel.TunnelWallEntity; | ||
import snownee.jade.api.IWailaClientRegistration; | ||
import snownee.jade.api.IWailaCommonRegistration; | ||
import snownee.jade.api.IWailaPlugin; | ||
import snownee.jade.api.WailaPlugin; | ||
|
||
@WailaPlugin | ||
public class JadePlugin implements IWailaPlugin { | ||
@Override | ||
public void register(IWailaCommonRegistration registration) { | ||
registration.registerBlockDataProvider(CompactMachineComponentProvider.INSTANCE, CompactMachineBlockEntity.class); | ||
registration.registerBlockDataProvider(TunnelComponentProvider.INSTANCE, TunnelWallEntity.class); | ||
} | ||
|
||
@Override | ||
public void registerClient(IWailaClientRegistration registration) { | ||
registration.registerBlockComponent(CompactMachineProvider.INSTANCE, CompactMachineBlock.class); | ||
registration.registerBlockComponent(TunnelProvider.INSTANCE, TunnelWallBlock.class); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...in/java/dev/compactmods/machines/compat/jade/providers/client/CompactMachineProvider.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,73 @@ | ||
package dev.compactmods.machines.compat.jade.providers.client; | ||
|
||
import dev.compactmods.machines.api.core.Constants; | ||
import dev.compactmods.machines.api.core.Tooltips; | ||
import dev.compactmods.machines.i18n.TranslationUtil; | ||
import dev.compactmods.machines.machine.CompactMachineBlockEntity; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.phys.Vec2; | ||
import snownee.jade.api.BlockAccessor; | ||
import snownee.jade.api.IBlockComponentProvider; | ||
import snownee.jade.api.ITooltip; | ||
import snownee.jade.api.config.IPluginConfig; | ||
import snownee.jade.api.ui.IElement; | ||
import snownee.jade.api.ui.IElementHelper; | ||
|
||
public class CompactMachineProvider implements IBlockComponentProvider { | ||
public static final CompactMachineProvider INSTANCE = new CompactMachineProvider(); | ||
|
||
@Override | ||
public void appendTooltip( | ||
ITooltip tooltip, | ||
BlockAccessor accessor, | ||
IPluginConfig config | ||
) { | ||
final CompactMachineBlockEntity machine = (CompactMachineBlockEntity) accessor.getBlockEntity(); | ||
machine.getConnectedRoom().ifPresentOrElse(room -> { | ||
tooltip.add(TranslationUtil.tooltip(Tooltips.Machines.BOUND_TO, room)); | ||
}, () -> { | ||
MutableComponent newMachine = TranslationUtil | ||
.message(new ResourceLocation(Constants.MOD_ID, "new_machine")) | ||
.withStyle(ChatFormatting.GREEN); | ||
tooltip.add(newMachine); | ||
}); | ||
|
||
machine.getOwnerUUID().ifPresent(ownerID -> { | ||
// Owner Name | ||
Player owner = accessor.getLevel().getPlayerByUUID(ownerID); | ||
if (owner != null) { | ||
MutableComponent ownerName = TranslationUtil | ||
.tooltip(Tooltips.Machines.OWNER, owner.getDisplayName()) | ||
.withStyle(ChatFormatting.GRAY); | ||
tooltip.add(ownerName); | ||
} | ||
}); | ||
|
||
if (accessor.getServerData().contains("attached_tunnels")) { | ||
ListTag tag = (ListTag) accessor.getServerData().get("attached_tunnels"); | ||
tooltip.add(Component.literal("")); // New Line | ||
tag.forEach(t -> { | ||
CompoundTag compound = (CompoundTag) t; | ||
ItemStack itemStack = ItemStack.of(compound); | ||
IElementHelper helper = tooltip.getElementHelper(); | ||
IElement icon = helper | ||
.item(itemStack) | ||
.size(new Vec2(15, 15)) | ||
.translate(new Vec2(-4, -3)); | ||
tooltip.append(icon); | ||
}); | ||
} | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return new ResourceLocation(Constants.MOD_ID, "machine"); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/dev/compactmods/machines/compat/jade/providers/client/TunnelProvider.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,56 @@ | ||
package dev.compactmods.machines.compat.jade.providers.client; | ||
|
||
import dev.compactmods.machines.api.core.Constants; | ||
import dev.compactmods.machines.tunnel.TunnelWallBlock; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.phys.Vec2; | ||
import snownee.jade.api.BlockAccessor; | ||
import snownee.jade.api.IBlockComponentProvider; | ||
import snownee.jade.api.ITooltip; | ||
import snownee.jade.api.config.IPluginConfig; | ||
import snownee.jade.api.ui.IElement; | ||
import snownee.jade.api.ui.IElementHelper; | ||
|
||
public class TunnelProvider implements IBlockComponentProvider { | ||
public static final TunnelProvider INSTANCE = new TunnelProvider(); | ||
|
||
@Override | ||
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) { | ||
Direction outSide = blockAccessor.getBlockState().getValue(TunnelWallBlock.CONNECTED_SIDE); | ||
|
||
IElementHelper helper = iTooltip.getElementHelper(); | ||
IElement compassIcon = helper | ||
.item(new ItemStack(Items.COMPASS), 1) | ||
.size(new Vec2(15, 15)).translate(new Vec2(0, -1)); | ||
iTooltip.add(compassIcon); | ||
|
||
String sideTranslated = Constants.MOD_ID + ".direction." + outSide.getName(); | ||
IElement directionText = helper | ||
.text(Component.translatable(sideTranslated)) | ||
.translate(new Vec2(5, 3)); | ||
iTooltip.append(directionText); | ||
|
||
if (blockAccessor.getServerData().contains("connected_block")) { | ||
ItemStack connectedBlockItemStack = | ||
ItemStack.of((CompoundTag) blockAccessor.getServerData().get("connected_block")); | ||
IElement itemIcon = helper | ||
.item(connectedBlockItemStack, 1) | ||
.size(new Vec2(15, 15)).translate(new Vec2(0, -1)); | ||
iTooltip.add(itemIcon); | ||
IElement itemName = helper | ||
.text(connectedBlockItemStack.getHoverName()) | ||
.translate(new Vec2(5, 3)); | ||
iTooltip.append(itemName); | ||
} | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return new ResourceLocation(Constants.MOD_ID, "tunnel"); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ev/compactmods/machines/compat/jade/providers/server/CompactMachineComponentProvider.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,51 @@ | ||
package dev.compactmods.machines.compat.jade.providers.server; | ||
|
||
import dev.compactmods.machines.api.core.Constants; | ||
import dev.compactmods.machines.api.dimension.CompactDimension; | ||
import dev.compactmods.machines.machine.CompactMachineBlockEntity; | ||
import dev.compactmods.machines.tunnel.TunnelItem; | ||
import dev.compactmods.machines.tunnel.graph.TunnelConnectionGraph; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.ListTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
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; | ||
|
||
public class CompactMachineComponentProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> { | ||
public static final CompactMachineComponentProvider INSTANCE = new CompactMachineComponentProvider(); | ||
|
||
@Override | ||
public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig config) { | ||
} | ||
|
||
@Override | ||
public void appendServerData(CompoundTag data, BlockAccessor accessor) { | ||
final CompactMachineBlockEntity machine = (CompactMachineBlockEntity) accessor.getBlockEntity(); | ||
machine.getConnectedRoom().ifPresent(room -> { | ||
final var compactDim = accessor.getLevel().getServer().getLevel(CompactDimension.LEVEL_KEY); | ||
final var graph = TunnelConnectionGraph.forRoom(compactDim, room); | ||
final var attachedTunnelsStream = graph.getTypesForSide(machine.getLevelPosition(), accessor.getSide()); | ||
|
||
ItemStack[] itemStackArray = attachedTunnelsStream | ||
.map(TunnelItem::createStack) | ||
.toArray(ItemStack[]::new); | ||
|
||
ListTag attachedTunnels = new ListTag(); | ||
for (ItemStack itemStack : itemStackArray) { | ||
CompoundTag tag = itemStack.save(new CompoundTag()); | ||
attachedTunnels.add(tag); | ||
} | ||
|
||
data.put("attached_tunnels", attachedTunnels); | ||
}); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return new ResourceLocation(Constants.MOD_ID, "machine_tunnels"); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...n/java/dev/compactmods/machines/compat/jade/providers/server/TunnelComponentProvider.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,52 @@ | ||
package dev.compactmods.machines.compat.jade.providers.server; | ||
|
||
import dev.compactmods.machines.api.core.Constants; | ||
import dev.compactmods.machines.api.location.IDimensionalBlockPosition; | ||
import dev.compactmods.machines.api.location.IDimensionalPosition; | ||
import dev.compactmods.machines.tunnel.TunnelWallEntity; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
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; | ||
|
||
public class TunnelComponentProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> { | ||
public static final TunnelComponentProvider INSTANCE = new TunnelComponentProvider(); | ||
|
||
@Override | ||
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) { | ||
} | ||
|
||
@Override | ||
public void appendServerData(CompoundTag data, BlockAccessor accessor) { | ||
final ServerLevel compactLevel = (ServerLevel) accessor.getLevel(); | ||
|
||
final TunnelWallEntity tunnelWallEntity = (TunnelWallEntity) accessor.getBlockEntity(); | ||
final IDimensionalBlockPosition machinePosition = tunnelWallEntity.getConnectedPosition(); | ||
final IDimensionalPosition connectedWorldPosition = machinePosition.relative(tunnelWallEntity.getConnectedSide()); | ||
|
||
final BlockState connectedBlockState = connectedWorldPosition | ||
.level(compactLevel.getServer()) | ||
.getBlockState(connectedWorldPosition.getBlockPosition()); | ||
|
||
final BlockEntity connectedBlockEntity = connectedWorldPosition | ||
.level(compactLevel.getServer()) | ||
.getBlockEntity(connectedWorldPosition.getBlockPosition()); | ||
|
||
if (!connectedBlockState.isAir()) { | ||
ItemStack connectedBlockItemStack = connectedBlockState.getBlock().asItem().getDefaultInstance(); | ||
data.put("connected_block", connectedBlockItemStack.save(new CompoundTag())); | ||
} | ||
} | ||
|
||
@Override | ||
public ResourceLocation getUid() { | ||
return new ResourceLocation(Constants.MOD_ID, "tunnel_connection"); | ||
} | ||
} |