Skip to content

Commit 4f42c22

Browse files
committed
Switch to using PERSISTED_NBT_TAG for players
Should fix all duped book problems
1 parent 12b9250 commit 4f42c22

File tree

3 files changed

+4
-39
lines changed

3 files changed

+4
-39
lines changed

src/main/java/modpacktweaks/ModpackTweaks.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import modpacktweaks.client.gui.GuiHelper;
99
import modpacktweaks.command.CommandMT;
1010
import modpacktweaks.config.ConfigurationHandler;
11-
import modpacktweaks.event.ModEventHandler;
1211
import modpacktweaks.event.PlayerTracker;
1312
import modpacktweaks.item.ModItems;
1413
import modpacktweaks.lib.Reference;
@@ -42,7 +41,6 @@ public class ModpackTweaks
4241
@SidedProxy(clientSide = "modpacktweaks.proxy.ClientProxy", serverSide = "modpacktweaks.proxy.CommonProxy")
4342
public static CommonProxy proxy;
4443

45-
public static ModEventHandler eventHandler;
4644
public static PlayerTracker playerTracker;
4745

4846
public static final Logger logger = Logger.getLogger("ModpackTweaks");
@@ -87,8 +85,6 @@ public void preInit(FMLPreInitializationEvent event)
8785
@EventHandler
8886
public void init(FMLInitializationEvent event)
8987
{
90-
eventHandler = new ModEventHandler();
91-
MinecraftForge.EVENT_BUS.register(eventHandler);
9288
ModItems.registerRecipes();
9389
}
9490

src/main/java/modpacktweaks/event/ModEventHandler.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
import modpacktweaks.client.gui.UpdateGui;
1111
import modpacktweaks.config.ConfigurationHandler;
1212
import net.minecraft.client.gui.GuiMainMenu;
13-
import net.minecraft.entity.player.EntityPlayer;
14-
import net.minecraft.nbt.NBTTagCompound;
1513
import net.minecraftforge.client.event.GuiOpenEvent;
1614
import net.minecraftforge.event.ForgeSubscribe;
17-
import net.minecraftforge.event.entity.living.LivingDeathEvent;
1815

1916
import com.google.common.collect.ImmutableList;
2017

@@ -24,7 +21,6 @@
2421

2522
public class ModEventHandler
2623
{
27-
public static boolean NBTValOnDeath;
2824
private String name, version, acronym;
2925

3026
public boolean shouldLoadGUI;
@@ -140,28 +136,4 @@ else if (s.contains("Forge") && !s.contains(":"))
140136
ModpackTweaks.logger.log(Level.WARNING, "Reflection error, " + acronym + " watermark will not be shown");
141137
}
142138
}
143-
144-
@ForgeSubscribe
145-
public void onLivingDeath(LivingDeathEvent event)
146-
{
147-
if (event.entityLiving instanceof EntityPlayer)
148-
{
149-
savePlayerNBT((EntityPlayer) event.entityLiving);
150-
}
151-
}
152-
153-
private void savePlayerNBT(EntityPlayer player)
154-
{
155-
ModpackTweaks.logger.log(Level.INFO, "getting NBT");
156-
157-
NBTValOnDeath = player.getEntityData().getCompoundTag("modpacktweaks").getBoolean("hasBook");
158-
}
159-
160-
public NBTTagCompound getTag(EntityPlayer entity, boolean useClassVal)
161-
{
162-
NBTTagCompound tag = new NBTTagCompound();
163-
tag.setBoolean("hasBook", useClassVal ? NBTValOnDeath : true);
164-
165-
return tag;
166-
}
167139
}

src/main/java/modpacktweaks/event/PlayerTracker.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,22 @@ public void onPlayerLogout(EntityPlayer player)
2727
@Override
2828
public void onPlayerChangedDimension(EntityPlayer player)
2929
{
30-
ModEventHandler.NBTValOnDeath = player.getEntityData().getCompoundTag("modpacktweaks").getBoolean("hasBook");
30+
// Do Nothing
3131
}
3232

3333
@Override
3434
public void onPlayerRespawn(EntityPlayer player)
3535
{
36-
ModpackTweaks.logger.log(Level.INFO, "adding NBT: " + ModEventHandler.NBTValOnDeath);
37-
player.getEntityData().setTag("modpacktweaks", ModpackTweaks.eventHandler.getTag(player, true));
38-
39-
addBook(player);
36+
// Do Nothing
4037
}
4138

4239
private boolean addBook(EntityPlayer player)
4340
{
44-
if (player != null && ConfigurationHandler.doSpawnBook && !player.getEntityData().getCompoundTag("modpacktweaks").getBoolean("hasBook") && !player.worldObj.isRemote)
41+
if (player != null && ConfigurationHandler.doSpawnBook && !player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG).getBoolean("MT:hasBook") && !player.worldObj.isRemote)
4542
{
4643
ModpackTweaks.logger.log(Level.INFO, "Adding book");
4744

48-
player.getEntityData().setTag("modpacktweaks", ModpackTweaks.eventHandler.getTag(player, false));
45+
player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG).setBoolean("MT:hasBook", true);
4946

5047
ItemStack stack = ModItems.book.getGuide();
5148
player.inventory.addItemStackToInventory(stack);

0 commit comments

Comments
 (0)