-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Added contents tooltip to minecarts so that Shulker minecarts…
… and packed minecarts can show their contents in tooltip similar to how backpacks do it
- Loading branch information
Showing
8 changed files
with
178 additions
and
2 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
11 changes: 11 additions & 0 deletions
11
src/main/java/net/p3pp3rf1y/sophisticatedstorageinmotion/client/ClientEventHandler.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 |
---|---|---|
@@ -1,22 +1,33 @@ | ||
package net.p3pp3rf1y.sophisticatedstorageinmotion.client; | ||
|
||
import net.minecraftforge.client.event.RegisterClientTooltipComponentFactoriesEvent; | ||
import net.minecraftforge.client.event.RegisterGuiOverlaysEvent; | ||
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.client.gui.MovingStorageScreen; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.client.gui.PaintbrushMovingStorageOverlay; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.item.MovingStorageItem; | ||
|
||
public class ClientEventHandler { | ||
private ClientEventHandler() { | ||
} | ||
|
||
public static void registerHandlers(IEventBus modBus) { | ||
modBus.addListener(ClientEventHandler::registerOverlay); | ||
modBus.addListener(ClientEventHandler::registerTooltipComponent); | ||
|
||
IEventBus eventBus = MinecraftForge.EVENT_BUS; | ||
eventBus.addListener(ClientMovingStorageContentsTooltip::onWorldLoad); | ||
|
||
net.p3pp3rf1y.sophisticatedstorage.client.ClientEventHandler.addSortScreenMatcher(screen -> screen instanceof MovingStorageScreen); | ||
} | ||
|
||
private static void registerOverlay(RegisterGuiOverlaysEvent event) { | ||
event.registerAbove(VanillaGuiOverlay.HOTBAR.id(), "paintbrush_moving_storage_info", PaintbrushMovingStorageOverlay.HUD_PAINTBRUSH_INFO); | ||
} | ||
|
||
private static void registerTooltipComponent(RegisterClientTooltipComponentFactoriesEvent event) { | ||
event.register(MovingStorageItem.MovingStorageContentsTooltip.class, ClientMovingStorageContentsTooltip::new); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...net/p3pp3rf1y/sophisticatedstorageinmotion/client/ClientMovingStorageContentsTooltip.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,38 @@ | ||
package net.p3pp3rf1y.sophisticatedstorageinmotion.client; | ||
|
||
import net.minecraft.client.gui.Font; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.event.level.LevelEvent; | ||
import net.p3pp3rf1y.sophisticatedcore.client.render.ClientStorageContentsTooltipBase; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.entity.MovingStorageWrapper; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.item.MovingStorageItem; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.network.RequestMovingStorageInventoryContentsMessage; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.network.StorageInMotionPacketHandler; | ||
|
||
import java.util.UUID; | ||
|
||
public class ClientMovingStorageContentsTooltip extends ClientStorageContentsTooltipBase { | ||
private final ItemStack movingStorage; | ||
|
||
@SuppressWarnings("unused") | ||
//parameter needs to be there so that addListener logic would know which event this method listens to | ||
public static void onWorldLoad(LevelEvent.Load event) { | ||
refreshContents(); | ||
lastRequestTime = 0; | ||
} | ||
|
||
@Override | ||
public void renderImage(Font font, int leftX, int topY, GuiGraphics guiGraphics) { | ||
renderTooltip(MovingStorageWrapper.fromStack(movingStorage, () -> {}, () -> {}), font, leftX, topY, guiGraphics); | ||
} | ||
|
||
public ClientMovingStorageContentsTooltip(MovingStorageItem.MovingStorageContentsTooltip tooltip) { | ||
movingStorage = tooltip.getMovingStorage(); | ||
} | ||
|
||
@Override | ||
protected void sendInventorySyncRequest(UUID uuid) { | ||
StorageInMotionPacketHandler.INSTANCE.sendToServer(new RequestMovingStorageInventoryContentsMessage(uuid)); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/main/java/net/p3pp3rf1y/sophisticatedstorageinmotion/item/MovingStorageItemClient.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,19 @@ | ||
package net.p3pp3rf1y.sophisticatedstorageinmotion.item; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.world.inventory.tooltip.TooltipComponent; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class MovingStorageItemClient { | ||
@Nullable | ||
public static TooltipComponent getTooltipImage(ItemStack stack) { | ||
Minecraft mc = Minecraft.getInstance(); | ||
if (Screen.hasShiftDown() || (mc.player != null && !mc.player.containerMenu.getCarried().isEmpty())) { | ||
return new MovingStorageItem.MovingStorageContentsTooltip(stack); | ||
} | ||
return null; | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
...1y/sophisticatedstorageinmotion/network/RequestMovingStorageInventoryContentsMessage.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,62 @@ | ||
package net.p3pp3rf1y.sophisticatedstorageinmotion.network; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraftforge.network.NetworkEvent; | ||
import net.p3pp3rf1y.sophisticatedcore.inventory.InventoryHandler; | ||
import net.p3pp3rf1y.sophisticatedcore.upgrades.UpgradeHandler; | ||
import net.p3pp3rf1y.sophisticatedstorage.block.StorageWrapper; | ||
import net.p3pp3rf1y.sophisticatedstorageinmotion.entity.MovingStorageData; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
|
||
public class RequestMovingStorageInventoryContentsMessage { | ||
private final UUID storageUuid; | ||
|
||
public RequestMovingStorageInventoryContentsMessage(UUID storageUuid) { | ||
this.storageUuid = storageUuid; | ||
} | ||
|
||
public static void encode(RequestMovingStorageInventoryContentsMessage msg, FriendlyByteBuf packetBuffer) { | ||
packetBuffer.writeUUID(msg.storageUuid); | ||
} | ||
|
||
public static RequestMovingStorageInventoryContentsMessage decode(FriendlyByteBuf packetBuffer) { | ||
return new RequestMovingStorageInventoryContentsMessage(packetBuffer.readUUID()); | ||
} | ||
|
||
static void onMessage(RequestMovingStorageInventoryContentsMessage msg, Supplier<NetworkEvent.Context> contextSupplier) { | ||
NetworkEvent.Context context = contextSupplier.get(); | ||
context.enqueueWork(() -> handleMessage(context.getSender(), msg)); | ||
context.setPacketHandled(true); | ||
} | ||
|
||
public static void handleMessage(@Nullable ServerPlayer player, RequestMovingStorageInventoryContentsMessage msg) { | ||
if (player == null) { | ||
return; | ||
} | ||
|
||
CompoundTag baseContentsTag = MovingStorageData.get(msg.storageUuid).getContents(); | ||
if (!baseContentsTag.contains(StorageWrapper.CONTENTS_TAG)) { | ||
return; | ||
} | ||
CompoundTag contentsTag = baseContentsTag.getCompound(StorageWrapper.CONTENTS_TAG); | ||
|
||
CompoundTag inventoryContents = new CompoundTag(); | ||
Tag inventoryNbt = contentsTag.get(InventoryHandler.INVENTORY_TAG); | ||
if (inventoryNbt != null) { | ||
inventoryContents.put(InventoryHandler.INVENTORY_TAG, inventoryNbt); | ||
} | ||
Tag upgradeNbt = contentsTag.get(UpgradeHandler.UPGRADE_INVENTORY_TAG); | ||
if (upgradeNbt != null) { | ||
inventoryContents.put(UpgradeHandler.UPGRADE_INVENTORY_TAG, upgradeNbt); | ||
} | ||
CompoundTag newBaseContentsTag = new CompoundTag(); | ||
newBaseContentsTag.put(StorageWrapper.CONTENTS_TAG, inventoryContents); | ||
StorageInMotionPacketHandler.INSTANCE.sendToClient(player, new MovingStorageContentsMessage(msg.storageUuid, newBaseContentsTag)); | ||
} | ||
} |
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