-
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.
Re-add current room debug and add in keybind for opening upgrade screen
- Loading branch information
1 parent
ac23278
commit 15e36a6
Showing
18 changed files
with
314 additions
and
213 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ain/src/main/java/dev/compactmods/machines/client/keybinds/room/RoomUpgradeUIMapping.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,42 @@ | ||
package dev.compactmods.machines.client.keybinds.room; | ||
|
||
import com.mojang.blaze3d.platform.InputConstants; | ||
import dev.compactmods.machines.api.CompactMachinesApi; | ||
import dev.compactmods.machines.api.dimension.CompactDimension; | ||
import dev.compactmods.machines.network.PlayerRequestedUpgradeUIPacket; | ||
import dev.compactmods.machines.room.Rooms; | ||
import net.minecraft.Util; | ||
import net.minecraft.client.KeyMapping; | ||
import net.minecraft.client.Minecraft; | ||
import net.neoforged.neoforge.client.settings.IKeyConflictContext; | ||
import net.neoforged.neoforge.network.PacketDistributor; | ||
|
||
public class RoomUpgradeUIMapping { | ||
|
||
public static final String CATEGORY = Util.makeDescriptionId("key.category", CompactMachinesApi.modRL("general")); | ||
public static final String NAME = Util.makeDescriptionId("key.mapping", CompactMachinesApi.modRL("open_upgrade_screen")); | ||
|
||
public static final IKeyConflictContext CONFLICT_CONTEXT = new IKeyConflictContext() { | ||
@Override | ||
public boolean isActive() { | ||
final var level = Minecraft.getInstance().level; | ||
return level != null && level.dimension().equals(CompactDimension.LEVEL_KEY); | ||
} | ||
|
||
@Override | ||
public boolean conflicts(IKeyConflictContext other) { | ||
return this == other; | ||
} | ||
}; | ||
|
||
public static final KeyMapping MAPPING = new KeyMapping(NAME, CONFLICT_CONTEXT, InputConstants.UNKNOWN, CATEGORY); | ||
|
||
public static void handle() { | ||
final var level = Minecraft.getInstance().level; | ||
final var player = Minecraft.getInstance().player; | ||
if (level != null && level.dimension().equals(CompactDimension.LEVEL_KEY)) { | ||
final var currentRoom = player.getData(Rooms.DataAttachments.CURRENT_ROOM_CODE); | ||
PacketDistributor.sendToServer(new PlayerRequestedUpgradeUIPacket(currentRoom, true)); | ||
} | ||
} | ||
} |
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
3 changes: 0 additions & 3 deletions
3
neoforge-main/src/main/java/dev/compactmods/machines/client/machine/MachinesClient.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,14 +1,11 @@ | ||
package dev.compactmods.machines.client.machine; | ||
|
||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.common.NeoForge; | ||
|
||
public interface MachinesClient { | ||
static void registerEvents(IEventBus modBus) { | ||
modBus.addListener(MachineClientEvents::registerMenuScreens); | ||
modBus.addListener(MachineClientEvents::onBlockColors); | ||
modBus.addListener(MachineClientEvents::onItemColors); | ||
|
||
NeoForge.EVENT_BUS.addListener(MachineClientEvents::handleKeybinds); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
neoforge-main/src/main/java/dev/compactmods/machines/client/room/RoomsClient.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,12 +1,15 @@ | ||
package dev.compactmods.machines.client.room; | ||
|
||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.neoforge.common.NeoForge; | ||
|
||
public interface RoomsClient { | ||
|
||
static void registerEvents(IEventBus modBus) { | ||
modBus.addListener(RoomClientEvents::registerMenuScreens); | ||
modBus.addListener(RoomClientEvents::onKeybindRegistration); | ||
modBus.addListener(RoomClientEvents::onOverlayRegistration); | ||
|
||
NeoForge.EVENT_BUS.addListener(RoomClientEvents::handleKeybinds); | ||
} | ||
} |
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
34 changes: 0 additions & 34 deletions
34
...main/src/main/java/dev/compactmods/machines/network/PlayerRequestedUpgradeMenuPacket.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...e-main/src/main/java/dev/compactmods/machines/network/PlayerRequestedUpgradeUIPacket.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,36 @@ | ||
package dev.compactmods.machines.network; | ||
|
||
import dev.compactmods.machines.api.CompactMachinesApi; | ||
import dev.compactmods.machines.api.room.RoomApi; | ||
import dev.compactmods.machines.room.ui.upgrades.RoomUpgradeMenu; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.neoforged.neoforge.network.handling.IPayloadHandler; | ||
|
||
public record PlayerRequestedUpgradeUIPacket(String roomCode, boolean isIsolated) implements CustomPacketPayload { | ||
|
||
public static final Type<PlayerRequestedUpgradeUIPacket> TYPE = new Type<>(CompactMachinesApi.modRL("player_wants_to_open_room_upgrade_menu")); | ||
|
||
public static final IPayloadHandler<PlayerRequestedUpgradeUIPacket> HANDLER = (pkt, ctx) -> { | ||
final var player = ctx.player(); | ||
RoomApi.room(pkt.roomCode()).ifPresent(inst -> { | ||
player.openMenu(RoomUpgradeMenu.provider(inst), buf -> { | ||
buf.writeBoolean(pkt.isIsolated); | ||
buf.writeUtf(pkt.roomCode()); | ||
}); | ||
}); | ||
}; | ||
|
||
public static final StreamCodec<FriendlyByteBuf, PlayerRequestedUpgradeUIPacket> STREAM_CODEC = StreamCodec.composite( | ||
ByteBufCodecs.STRING_UTF8, PlayerRequestedUpgradeUIPacket::roomCode, | ||
ByteBufCodecs.BOOL, PlayerRequestedUpgradeUIPacket::isIsolated, | ||
PlayerRequestedUpgradeUIPacket::new | ||
); | ||
|
||
@Override | ||
public Type<? extends CustomPacketPayload> type() { | ||
return TYPE; | ||
} | ||
} |
Oops, something went wrong.