generated from JamCoreModding/multi-loader-template-mod
-
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.
feat: my random changes, to be merged with the main branch in a bit
- Loading branch information
1 parent
148c136
commit 48f6bef
Showing
25 changed files
with
312 additions
and
416 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
- Update to 1.21 | ||
- Switch to using the [Accessories](https://modrinth.com/mod/accessories) mod. See its mod page for information on compatibility with existing mods using Trinkets and Curios. | ||
- Fix hotbar rendering even when F1 is pressed. | ||
- Fix server crash (#48). | ||
- Move config client side, since all of its options were only applicable there. | ||
|
||
In addition, several other issues have been fixed related to network synchronization. |
74 changes: 54 additions & 20 deletions
74
common/src/main/java/io/github/jamalam360/utility_belt/StateManager.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,46 +1,80 @@ | ||
package io.github.jamalam360.utility_belt; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public abstract class StateManager { | ||
private static StateManager clientInstance; | ||
private static StateManager serverInstance; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public static StateManager getClientInstance() { | ||
return clientInstance; | ||
public class StateManager { | ||
private static final StateManager instance = new StateManager(); | ||
private final Map<UUID, PlayerState> playerStates = new Object2ObjectArrayMap<>(); | ||
|
||
public static StateManager getInstance() { | ||
return instance; | ||
} | ||
|
||
public static void setClientInstance(StateManager clientInstance) { | ||
StateManager.clientInstance = clientInstance; | ||
public boolean hasBelt(Player player) { | ||
ItemStack belt = UtilityBeltItem.getBelt(player); | ||
return belt != null && belt.is(UtilityBelt.UTILITY_BELT_ITEM.get()); | ||
} | ||
|
||
private PlayerState getState(Player player) { | ||
return playerStates.computeIfAbsent(player.getUUID(), uuid -> new PlayerState(false, 0)); | ||
} | ||
|
||
public static StateManager getServerInstance() { | ||
return serverInstance; | ||
public boolean isInBelt(Player player) { | ||
return getState(player).inBelt; | ||
} | ||
|
||
public static void setServerInstance(StateManager serverInstance) { | ||
StateManager.serverInstance = serverInstance; | ||
public void setInBelt(Player player, boolean inBelt) { | ||
getState(player).inBelt = inBelt; | ||
} | ||
|
||
public boolean hasBelt(Player player) { | ||
ItemStack belt = UtilityBeltItem.getBelt(player); | ||
return belt != null && belt.is(UtilityBelt.UTILITY_BELT_ITEM.get()); | ||
public int getSelectedBeltSlot(Player player) { | ||
return getState(player).selectedBeltSlot; | ||
} | ||
|
||
public abstract boolean isInBelt(Player player); | ||
public void setSelectedBeltSlot(Player player, int slot) { | ||
getState(player).selectedBeltSlot = slot; | ||
} | ||
|
||
public UtilityBeltInventory getInventory(Player player) { | ||
PlayerState state = getState(player); | ||
|
||
public abstract void setInBelt(Player player, boolean inBelt); | ||
if (state.inventory == null) { | ||
ItemStack belt = UtilityBeltItem.getBelt(player); | ||
|
||
public abstract int getSelectedBeltSlot(Player player); | ||
if (belt == null) { | ||
return UtilityBeltInventory.EMPTY; | ||
} | ||
|
||
public abstract void setSelectedBeltSlot(Player player, int slot); | ||
state.inventory = UtilityBeltItem.getInventory(belt); | ||
} | ||
|
||
public abstract UtilityBeltInventory getInventory(Player player); | ||
return state.inventory; | ||
} | ||
|
||
public UtilityBeltInventory.Mutable getMutableInventory(Player player) { | ||
return new UtilityBeltInventory.Mutable(this.getInventory(player)); | ||
} | ||
|
||
public abstract void setInventory(Player player, UtilityBeltInventory.Mutable inventory); | ||
public void setInventory(Player player, UtilityBeltInventory.Mutable inventory) { | ||
getState(player).inventory = inventory.toImmutable(); | ||
} | ||
|
||
private static class PlayerState { | ||
boolean inBelt; | ||
int selectedBeltSlot; | ||
@Nullable | ||
UtilityBeltInventory inventory; | ||
|
||
PlayerState(boolean inBelt, int selectedBeltSlot) { | ||
this.inBelt = inBelt; | ||
this.selectedBeltSlot = selectedBeltSlot; | ||
this.inventory = 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
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
Oops, something went wrong.