mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-28 07:35:46 +00:00
Merge remote-tracking branch 'origin/master' into sync
This commit is contained in:
commit
edfad61553
5 files changed
+40
-6
No files matched your search
@@ -3,8 +3,10 @@ package baubles.common;
|
||||
import java.io.File;
|
||||
|
||||
import baubles.Tags;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import codechicken.nei.api.API;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -75,4 +77,9 @@ public class Baubles {
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStopped(FMLServerStoppedEvent event) {
|
||||
PlayerHandler.clearServerPlayerBaubles();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -295,7 +295,7 @@ public class InventoryBaubles implements IInventory {
|
||||
|
||||
public void syncSlotToClients(int slot) {
|
||||
try {
|
||||
EntityPlayer entityPlayer = player.get();
|
||||
final EntityPlayer entityPlayer = this.player.get();
|
||||
if (entityPlayer instanceof EntityPlayerMP playerMP && !entityPlayer.worldObj.isRemote) {
|
||||
PacketHandler.sendToTracking(new PacketSyncBauble(playerMP, slot), playerMP, true);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
public class EventHandlerEntity {
|
||||
|
||||
@@ -102,6 +103,11 @@ public class EventHandlerEntity {
|
||||
getPlayerFile("baubback", directory, player.getCommandSenderName()));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldUnload(WorldEvent.Unload event) {
|
||||
PlayerHandler.onWorldUnload(event.world);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void startTracking(PlayerEvent.StartTracking event) {
|
||||
// no need to check for isRemote: this event is server only
|
||||
|
||||
@@ -12,6 +12,7 @@ import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import baubles.common.network.PacketSyncBauble;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class EventHandlerNetwork {
|
||||
@@ -33,6 +34,13 @@ public class EventHandlerNetwork {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerChangedDim(PlayerEvent.PlayerChangedDimensionEvent event) {
|
||||
if (event.player instanceof EntityPlayerMP playerMP) {
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncAllBauble(playerMP), playerMP);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConnectedToServer(FMLNetworkEvent.ClientConnectedToServerEvent event) {
|
||||
// clear old cache
|
||||
@@ -41,10 +49,9 @@ public class EventHandlerNetwork {
|
||||
|
||||
public static void syncBaubles(EntityPlayer player) {
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
|
||||
for (int i = 0; i < baubles.getSizeInventory(); i++) {
|
||||
baubles.syncSlotToClients(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < baubles.getSizeInventory(); i++) {
|
||||
baubles.syncSlotToClients(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PlayerHandler {
|
||||
|
||||
@@ -68,6 +69,19 @@ public class PlayerHandler {
|
||||
map.remove(playerName);
|
||||
}
|
||||
|
||||
public static void clearServerPlayerBaubles() {
|
||||
playerBaublesServer.clear();
|
||||
}
|
||||
|
||||
public static void onWorldUnload(World world) {
|
||||
if (world.isRemote) {
|
||||
playerBaublesClient.values().removeIf(inv -> {
|
||||
final EntityPlayer player = inv.player.get();
|
||||
return player == null || player.worldObj == world;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static InventoryBaubles getPlayerBaubles(EntityPlayer player) {
|
||||
if (player.worldObj.isRemote) {
|
||||
return playerBaublesClient.computeIfAbsent(player.getCommandSenderName(), username -> new InventoryBaubles(player));
|
||||
|
||||
Reference in new issue
Block a user