56 lines
2.8 KiB
Java
56 lines
2.8 KiB
Java
package jesse.keeblarcraft.EventMgr;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map.Entry;
|
|
|
|
import jesse.keeblarcraft.world.dimension.ModDimensions;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.entity.player.PlayerInventory;
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.server.world.ServerWorld;
|
|
|
|
public class DimensionLoadingEvent {
|
|
|
|
// private static List<Inventory> inventories = new ArrayList<Inventory>();
|
|
public static HashMap<String, PlayerInventory> inventories = new HashMap<String, PlayerInventory>();
|
|
|
|
// TODO: In the future when the attribute system is more complete this will need to filter a whitelist of items
|
|
// from the that system + story mode because some items will be able to transcend dimensions!
|
|
public static void HandleWorldMove(ServerPlayerEntity player, ServerWorld origin, ServerWorld destination) {
|
|
if (destination.getDimensionEntry().matchesKey(ModDimensions.KEEBLAR_DIM_TYPE)) {
|
|
// Make sure player is in map. For now we only care about storing OVERWORLD inventory. We DO NOT care about
|
|
// the dimension inventory!
|
|
if (!inventories.containsKey(player.getUuidAsString())) {
|
|
PlayerInventory copyInv = new PlayerInventory(player);
|
|
copyInv.clone(player.getInventory());
|
|
inventories.put(player.getUuidAsString(), copyInv);
|
|
player.getInventory().clear();
|
|
} else {
|
|
System.out.println("Player in system. Ignoring");
|
|
}
|
|
} else if (origin.getDimensionEntry().matchesKey(ModDimensions.KEEBLAR_DIM_TYPE)) {
|
|
if (inventories.containsKey(player.getUuidAsString())) {
|
|
System.out.println("Player is in map. Cloning our inventory back to them...");
|
|
player.getInventory().clone(inventories.get(player.getUuidAsString()));
|
|
inventories.remove(player.getUuidAsString());
|
|
} else {
|
|
System.out.println("Player not in system. Ignoring");
|
|
}
|
|
} else {
|
|
System.out.println("dest TYPE - KEY" + destination.getDimensionEntry().getType().toString() + " -- " + destination.getDimensionEntry().getKey().toString());
|
|
System.out.println("orig TYPE - KEY: " + origin.getDimensionEntry().getType().toString() + " -- "+ origin.getDimensionEntry().getKey().toString());
|
|
}
|
|
}
|
|
|
|
// needs to be tested
|
|
public static void ResetInventories() {
|
|
System.out.println("ResetInventories: inventory size: " + inventories.size());
|
|
for (Entry<String, PlayerInventory> entry : inventories.entrySet()) {
|
|
PlayerEntity player = entry.getValue().player;
|
|
|
|
System.out.println("Found PlayerEntity");
|
|
player.getInventory().clone(entry.getValue());
|
|
}
|
|
}
|
|
}
|