mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-20 12:09:59 +00:00
Some bugfixes and improvements
This commit is contained in:
1 parent
ff405853bf
commit
f975878a32
20 files changed
+68
-51
No files matched your search
@@ -1,14 +1,34 @@
|
||||
package baubles.api;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Azanor
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class BaublesApi {
|
||||
|
||||
static Method getBaubles;
|
||||
/**
|
||||
* Retrieves the baubles inventory for the supplied player
|
||||
*/
|
||||
public static IInventory getBaubles(EntityPlayer player) {
|
||||
IInventory ot = null;
|
||||
try {
|
||||
if(getBaubles == null) {
|
||||
Class fake = Class.forName("baubles.common.lib.PlayerHandler");
|
||||
getBaubles = fake.getMethod("getPlayerBaubles", EntityPlayer.class);
|
||||
}
|
||||
ot = (IInventory) getBaubles.invoke(null, player);
|
||||
} catch(Exception ex) {
|
||||
FMLLog.warning("[Baubles API] Could not invoke baubles.common.lib.PlayerHandler method getPlayerBaubles");
|
||||
}
|
||||
return ot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package baubles.client.gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.achievement.GuiAchievements;
|
||||
import net.minecraft.client.gui.achievement.GuiStats;
|
||||
import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
||||
import net.minecraft.client.renderer.InventoryEffectRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
@@ -45,10 +44,10 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
if (this.mc.playerController.isInCreativeMode())
|
||||
{
|
||||
this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer));
|
||||
}
|
||||
// if (this.mc.playerController.isInCreativeMode())
|
||||
// {
|
||||
// this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer));
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,14 +58,14 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
|
||||
{
|
||||
this.buttonList.clear();
|
||||
|
||||
if (this.mc.playerController.isInCreativeMode())
|
||||
{
|
||||
this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer));
|
||||
}
|
||||
else
|
||||
{
|
||||
// if (this.mc.playerController.isInCreativeMode())
|
||||
// {
|
||||
// this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer));
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
super.initGui();
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,14 +2,12 @@ package baubles.common;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import baubles.common.event.EventHandlerEntity;
|
||||
import baubles.common.lib.CreativeTabBaubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import baubles.common.network.EventHandlerNetwork;
|
||||
import baubles.common.network.PacketPipeline;
|
||||
@@ -40,13 +38,11 @@ public class Baubles {
|
||||
|
||||
public EventHandlerNetwork networkEventHandler;
|
||||
public EventHandlerEntity entityEventHandler;
|
||||
public PlayerHandler playerHandler;
|
||||
public File modDir;
|
||||
|
||||
public static final PacketPipeline packetPipeline = new PacketPipeline();
|
||||
public static final Logger logger = LogManager.getLogger("Baubles");
|
||||
public static final int GUI = 0;
|
||||
public static CreativeTabs tabBaubles = new CreativeTabBaubles(CreativeTabs.getNextID(), "baubles");
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
@@ -62,7 +58,6 @@ public class Baubles {
|
||||
}
|
||||
|
||||
entityEventHandler = new EventHandlerEntity();
|
||||
playerHandler = new PlayerHandler();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(entityEventHandler);
|
||||
FMLCommonHandler.instance().bus().register(new EventHandlerNetwork());
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import baubles.common.Baubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
|
||||
public class ContainerPlayerExpanded extends Container
|
||||
{
|
||||
@@ -36,7 +36,7 @@ public class ContainerPlayerExpanded extends Container
|
||||
baubles = new InventoryBaubles(player);
|
||||
baubles.setEventHandler(this);
|
||||
if (!player.worldObj.isRemote) {
|
||||
baubles.stackList = Baubles.instance.playerHandler.getPlayerBaubles(player).stackList;
|
||||
baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList;
|
||||
}
|
||||
|
||||
this.addSlotToContainer(new SlotCrafting(playerInv.player, this.craftMatrix, this.craftResult, 0, 144, 36));
|
||||
@@ -117,8 +117,8 @@ public class ContainerPlayerExpanded extends Container
|
||||
|
||||
this.craftResult.setInventorySlotContents(0, (ItemStack)null);
|
||||
if (!player.worldObj.isRemote) {
|
||||
Baubles.instance.playerHandler.setPlayerBaubles(player, baubles);
|
||||
Baubles.instance.playerHandler.updatePlayerBaubles(player);
|
||||
PlayerHandler.setPlayerBaubles(player, baubles);
|
||||
PlayerHandler.updatePlayerBaubles(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public class ContainerPlayerExpanded extends Container
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (itemstack.getItem() instanceof IBauble &&
|
||||
else if (par2>11 && itemstack.getItem() instanceof IBauble &&
|
||||
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING &&
|
||||
!((Slot)this.inventorySlots.get(10)).getHasStack())
|
||||
{
|
||||
@@ -195,7 +195,7 @@ public class ContainerPlayerExpanded extends Container
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (itemstack.getItem() instanceof IBauble &&
|
||||
else if (par2>11 && itemstack.getItem() instanceof IBauble &&
|
||||
((IBauble)itemstack.getItem()).getBaubleType(itemstack)==BaubleType.RING &&
|
||||
!((Slot)this.inventorySlots.get(11)).getHasStack())
|
||||
{
|
||||
|
||||
@@ -4,8 +4,8 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import baubles.api.IBauble;
|
||||
import baubles.common.Baubles;
|
||||
import baubles.common.container.InventoryBaubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
public class EventHandlerEntity {
|
||||
@@ -17,7 +17,7 @@ public class EventHandlerEntity {
|
||||
if (event.entity instanceof EntityPlayer) {
|
||||
EntityPlayer player = (EntityPlayer)event.entity;
|
||||
|
||||
InventoryBaubles baubles = Baubles.instance.playerHandler.getPlayerBaubles(player);
|
||||
InventoryBaubles baubles = PlayerHandler.getPlayerBaubles(player);
|
||||
for (int a=0;a<baubles.getSizeInventory();a++) {
|
||||
if (baubles.getStackInSlot(a)!=null && baubles.getStackInSlot(a).getItem() instanceof IBauble) {
|
||||
((IBauble)baubles.getStackInSlot(a).getItem()).onWornTick(baubles.getStackInSlot(a), player);
|
||||
@@ -30,9 +30,9 @@ public class EventHandlerEntity {
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerDeath(LivingDeathEvent event) {
|
||||
if (event.entity instanceof EntityPlayer) {
|
||||
if (event.entity instanceof EntityPlayer && !event.entity.worldObj.isRemote) {
|
||||
EntityPlayer player = (EntityPlayer)event.entity;
|
||||
Baubles.instance.playerHandler.getPlayerBaubles(player).dropItems(player);
|
||||
PlayerHandler.getPlayerBaubles(player).dropItems(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package baubles.common.event;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.network.play.client.C16PacketClientStatus;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@@ -27,10 +30,15 @@ public class KeyHandler {
|
||||
@SubscribeEvent
|
||||
public void playerTick(PlayerTickEvent event) {
|
||||
if (event.side == Side.SERVER) return;
|
||||
if (event.phase == Phase.START) {
|
||||
if (event.phase == Phase.START ) {
|
||||
if (key.getIsKeyPressed() && FMLClientHandler.instance().getClient().inGameHasFocus) {
|
||||
Baubles.packetPipeline.sendToServer(new PacketOpenBaublesInventory(event.player));
|
||||
// event.player.openGui(Baubles.instance, Baubles.GUI, event.player.worldObj, 0, 0, 0);
|
||||
if (!event.player.capabilities.isCreativeMode)
|
||||
Baubles.packetPipeline.sendToServer(new PacketOpenBaublesInventory(event.player));
|
||||
else {
|
||||
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT));
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiContainerCreative(event.player));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.IIcon;
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import baubles.common.Baubles;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -26,7 +25,7 @@ public class ItemRing extends Item implements IBauble
|
||||
this.setMaxStackSize(1);
|
||||
this.setHasSubtypes(true);
|
||||
this.setMaxDamage(0);
|
||||
setCreativeTab(Baubles.tabBaubles);
|
||||
setCreativeTab(CreativeTabs.tabTools);
|
||||
}
|
||||
|
||||
public IIcon icon;
|
||||
|
||||
@@ -7,9 +7,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import baubles.common.container.InventoryBaubles;
|
||||
|
||||
public class PlayerHandler {
|
||||
private HashMap<String,InventoryBaubles> playerBaubles = new HashMap<String,InventoryBaubles>();
|
||||
private static HashMap<String,InventoryBaubles> playerBaubles = new HashMap<String,InventoryBaubles>();
|
||||
|
||||
public InventoryBaubles getPlayerBaubles(EntityPlayer player) {
|
||||
public static InventoryBaubles getPlayerBaubles(EntityPlayer player) {
|
||||
if (!playerBaubles.containsKey(player.getCommandSenderName())) {
|
||||
InventoryBaubles inventory = new InventoryBaubles(player);
|
||||
playerBaubles.put(player.getCommandSenderName(), inventory);
|
||||
@@ -17,16 +17,16 @@ public class PlayerHandler {
|
||||
return playerBaubles.get(player.getCommandSenderName());
|
||||
}
|
||||
|
||||
public void setPlayerBaubles(EntityPlayer player, InventoryBaubles inventory) {
|
||||
public static void setPlayerBaubles(EntityPlayer player, InventoryBaubles inventory) {
|
||||
playerBaubles.put(player.getCommandSenderName(), inventory);
|
||||
}
|
||||
|
||||
public void updatePlayerBaubles(EntityPlayer player) {
|
||||
public static void updatePlayerBaubles(EntityPlayer player) {
|
||||
InventoryBaubles inventory = getPlayerBaubles(player);
|
||||
inventory.saveNBT(player);
|
||||
}
|
||||
|
||||
public void loadPlayerBaubles(EntityPlayer player) {
|
||||
public static void loadPlayerBaubles(EntityPlayer player) {
|
||||
NBTTagCompound data = player.getEntityData();
|
||||
if (!data.hasKey("Baubles")) {
|
||||
data.setTag("Baubles", new NBTTagCompound());
|
||||
|
||||
@@ -2,7 +2,7 @@ package baubles.common.network;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import baubles.common.Baubles;
|
||||
import baubles.common.lib.PlayerHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
@@ -14,7 +14,7 @@ public class EventHandlerNetwork {
|
||||
public void playerLoggedInEvent (PlayerEvent.PlayerLoggedInEvent event) {
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.SERVER) {
|
||||
Baubles.instance.playerHandler.loadPlayerBaubles(event.player);
|
||||
PlayerHandler.loadPlayerBaubles(event.player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class EventHandlerNetwork {
|
||||
public void playerUpdateEvent (PlayerEvent event) {
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
if (side == Side.SERVER) {
|
||||
Baubles.instance.playerHandler.updatePlayerBaubles(event.player);
|
||||
PlayerHandler.updatePlayerBaubles(event.player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user