Bug fixes

This commit is contained in:
John Yorke committed 2017-08-18 00:28:08 -03:00
1 parent 68ea7a345d
commit 54f79497e0
7 files changed
+214 -85

No files matched your search

@@ -1,8 +1,8 @@
package taintedmagic.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import taintedmagic.client.handler.HUDHandler;
@@ -19,6 +19,7 @@ import taintedmagic.common.entities.EntityHomingShard;
import taintedmagic.common.entities.EntityTaintBubble;
import taintedmagic.common.registry.ItemRegistry;
import thaumcraft.client.renderers.entity.RenderEldritchOrb;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -53,8 +54,8 @@ public class ClientProxy extends CommonProxy
}
@Override
public WorldClient getClientWorld ()
public World getClientWorld ()
{
return Minecraft.getMinecraft().theWorld;
return FMLClientHandler.instance().getClient().theWorld;
}
}
@@ -19,7 +19,7 @@ public class CommonProxy
return null;
}
public WorldClient getClientWorld ()
public World getClientWorld ()
{
return null;
}
@@ -1,18 +1,18 @@
package taintedmagic.common.helper;
import baubles.api.BaublesApi;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess;
import taintedmagic.common.TaintedMagic;
import taintedmagic.common.network.PacketHandler;
import taintedmagic.common.network.PacketSyncInv;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.codechicken.lib.vec.Vector3;
import thaumcraft.common.items.baubles.ItemAmuletVis;
import thaumcraft.common.items.wands.ItemWandCasting;
import baubles.api.BaublesApi;
public class TaintedMagicHelper
{
@@ -44,6 +44,18 @@ public class TaintedMagicHelper
return false;
}
public static void syncSlotToClients (EntityPlayer p)
{
try
{
if (TaintedMagic.proxy.getClientWorld() == null) PacketHandler.INSTANCE.sendToAll(new PacketSyncInv(p));
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static Vector3 getDistanceBetween (Entity e, Entity target)
{
Vector3 fromPosition = new Vector3(e.posX, e.posY, e.posZ);
@@ -4,27 +4,27 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent;
import org.lwjgl.opengl.GL11;
import taintedmagic.client.renderer.RenderItemKatana;
import taintedmagic.common.TaintedMagic;
import taintedmagic.common.helper.TaintedMagicHelper;
import taintedmagic.common.items.tools.ItemKatana;
import taintedmagic.common.network.PacketHandler;
import taintedmagic.common.network.PacketSyncInv;
import thaumcraft.api.IWarpingGear;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
@@ -39,15 +39,16 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ItemFlyteCharm extends Item implements IWarpingGear
{
boolean isFlying = false;
boolean synced = false;
static final int burstCooldown = 40;
static final int maxBurstCooldown = 40;
static final AspectList cost = new AspectList().add(Aspect.AIR, 10);
static final String TAG_SPRINTING = "isSprinting";
static final String TAG_COOLDOWN = "cooldown";
// Flight manager
List<String> playersWithFlight = new ArrayList();
static List<String> playersWithFlight = new ArrayList();
private static final ResourceLocation circle = new ResourceLocation("taintedmagic:textures/misc/circle.png");
@@ -56,6 +57,7 @@ public class ItemFlyteCharm extends Item implements IWarpingGear
this.setCreativeTab(TaintedMagic.tabTaintedMagic);
this.setUnlocalizedName("ItemFlyteCharm");
this.setMaxStackSize(1);
this.setTextureName("taintedmagic:ItemFlyteCharm");
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
@@ -67,18 +69,6 @@ public class ItemFlyteCharm extends Item implements IWarpingGear
return TaintedMagic.rarityCreation;
}
@Override
public void addInformation (ItemStack s, EntityPlayer p, List l, boolean b)
{
}
@Override
@SideOnly (Side.CLIENT)
public void registerIcons (IIconRegister ir)
{
itemIcon = ir.registerIcon("taintedmagic:ItemFlyteCharm");
}
// Flight manager
@SubscribeEvent
public void updateFlight (LivingEvent.LivingUpdateEvent event)
@@ -113,20 +103,34 @@ public class ItemFlyteCharm extends Item implements IWarpingGear
ItemStack s = null;
for (int i = 0; i < p.inventory.getSizeInventory(); i++)
for (int i = 0; i < p.inventory.mainInventory.length; i++)
{
if (p.inventory.getStackInSlot(i) != null && p.inventory.getStackInSlot(i).getItem() instanceof ItemFlyteCharm)
if (p.inventory.mainInventory[i] != null && p.inventory.mainInventory[i].getItem() instanceof ItemFlyteCharm)
{
s = p.inventory.getStackInSlot(i);
if (!this.synced)
{
// sync slot to other players
TaintedMagicHelper.syncSlotToClients(p.inventory.player);
this.synced = true;
}
s = p.inventory.mainInventory[i];
break;
}
else s = null;
else
{
if (this.synced)
{
TaintedMagicHelper.syncSlotToClients(p.inventory.player);
this.synced = false;
}
s = null;
}
}
if (s != null)
{
if (s.stackTagCompound == null) s.stackTagCompound = new NBTTagCompound();
// Sprint stuff
boolean wasSprinting = s.stackTagCompound.getBoolean(TAG_SPRINTING);
boolean isSprinting = p.isSprinting();
@@ -157,12 +161,12 @@ public class ItemFlyteCharm extends Item implements IWarpingGear
p.motionX += look.x * 1.5D;
p.motionZ += look.z * 1.5D;
setBurstCooldown(s, this.burstCooldown);
setBurstCooldown(s, this.maxBurstCooldown);
}
else if (getBurstCooldown(s) > 0)
{
if (this.burstCooldown - getBurstCooldown(s) < 2) p.moveFlying(0F, 1.0F, 5.0F);
else if (this.burstCooldown - getBurstCooldown(s) < 10) p.setSprinting(false);
if (this.maxBurstCooldown - getBurstCooldown(s) < 2) p.moveFlying(0F, 1.0F, 5.0F);
else if (this.maxBurstCooldown - getBurstCooldown(s) < 10) p.setSprinting(false);
}
}
else
@@ -190,12 +194,11 @@ public class ItemFlyteCharm extends Item implements IWarpingGear
playersWithFlight.remove(username + ":true");
}
public String playerStr (EntityPlayer p)
private String playerStr (EntityPlayer p)
{
return p.getGameProfile().getName() + ":" + p.worldObj.isRemote;
}
// player flight status
private boolean shouldPlayerHaveFlight (EntityPlayer p)
{
for (int i = 0; i < p.inventory.getSizeInventory(); i++)
@@ -203,45 +206,49 @@ public class ItemFlyteCharm extends Item implements IWarpingGear
return false;
}
public void setBurstCooldown (ItemStack s, int cooldown)
private void setBurstCooldown (ItemStack s, int cooldown)
{
if (s.stackTagCompound == null) s.stackTagCompound = new NBTTagCompound();
s.getTagCompound().setInteger(TAG_COOLDOWN, cooldown);
}
public float getBurstCooldown (ItemStack s)
private float getBurstCooldown (ItemStack s)
{
if (s.stackTagCompound == null) s.stackTagCompound = new NBTTagCompound();
return s.stackTagCompound.getInteger(TAG_COOLDOWN);
}
@SideOnly (Side.CLIENT)
@Override
public int getWarp (ItemStack s, EntityPlayer p)
{
return 5;
}
@SubscribeEvent
public void onPlayerRender (RenderPlayerEvent.Specials.Post event)
@SideOnly (Side.CLIENT)
public void renderPlayer (RenderPlayerEvent.Specials.Post event)
{
EntityPlayer p = event.entityPlayer;
if (p.getActivePotionEffect(Potion.invisibility) != null) return;
boolean render = false;
ItemStack s = null;
for (int i = 0; i < p.inventory.getSizeInventory(); i++)
{
if (p.inventory.getStackInSlot(i) != null && p.inventory.getStackInSlot(i).getItem() instanceof ItemFlyteCharm)
{
render = true;
s = p.inventory.getStackInSlot(i);
break;
}
else render = false;
else s = null;
}
if (render)
if (s != null)
{
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if (p.isSneaking()) GL11.glRotatef(28.64789F, 1.0F, 0.0F, 0.0F);
GL11.glTranslated(0, (p != Minecraft.getMinecraft().thePlayer ? 1.62F : 0F) - p.getDefaultEyeHeight() + (p.isSneaking() ? 0.0625 : 0), 0);
GL11.glRotatef(45, -1, 0, -1);
@@ -277,10 +284,4 @@ public class ItemFlyteCharm extends Item implements IWarpingGear
GL11.glPopMatrix();
}
}
@Override
public int getWarp (ItemStack s, EntityPlayer p)
{
return 5;
}
}
@@ -27,6 +27,7 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -35,12 +36,15 @@ import taintedmagic.client.model.ModelKatana;
import taintedmagic.client.model.ModelSaya;
import taintedmagic.common.TaintedMagic;
import taintedmagic.common.entities.EntityTaintBubble;
import taintedmagic.common.helper.TaintedMagicHelper;
import taintedmagic.common.items.ItemFlyteCharm;
import taintedmagic.common.network.PacketHandler;
import taintedmagic.common.network.PacketKatanaAttack;
import thaumcraft.api.IRepairable;
import thaumcraft.api.IWarpingGear;
import thaumcraft.common.config.Config;
import thaumcraft.common.entities.projectile.EntityExplosiveOrb;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -57,8 +61,8 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable
public static final ModelSaya saya = new ModelSaya();
static float ticksEquipped = 0F;
int ticksInUse = 0;
boolean synced = false;
public ItemKatana ()
{
@@ -68,6 +72,37 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable
this.setMaxStackSize(1);
MinecraftForge.EVENT_BUS.register(this);
FMLCommonHandler.instance().bus().register(this);
}
@SubscribeEvent
public void playerTick (LivingEvent.LivingUpdateEvent event)
{
if (event.entityLiving instanceof EntityPlayer)
{
EntityPlayer p = (EntityPlayer) event.entityLiving;
for (int i = 0; i < p.inventory.mainInventory.length; i++)
{
if (p.inventory.mainInventory[i] != null && p.inventory.mainInventory[i].getItem() instanceof ItemKatana)
{
if (!this.synced)
{
// sync slot to other players
TaintedMagicHelper.syncSlotToClients(p.inventory.player);
this.synced = true;
}
break;
}
else
{
if (this.synced)
{
TaintedMagicHelper.syncSlotToClients(p.inventory.player);
this.synced = false;
}
}
}
}
}
@Override
@@ -290,24 +325,45 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable
public void onPlayerRender (RenderPlayerEvent.Specials.Post event)
{
EntityPlayer p = event.entityPlayer;
if (p.getActivePotionEffect(Potion.invisibility) != null) return;
ItemStack s = null;
for (int i = 0; i < p.inventory.getSizeInventory(); i++)
{
if (p.inventory.getStackInSlot(i) != null && p.inventory.getStackInSlot(i).getItem() instanceof ItemKatana)
{
ItemStack s = p.inventory.getStackInSlot(i);
s = p.inventory.getStackInSlot(i);
break;
}
else s = null;
}
GL11.glPushMatrix();
if (s != null)
{
GL11.glPushMatrix();
int light = p.getBrightnessForRender(0);
int lightmapX = light % 65536;
int lightmapY = light / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapX, lightmapY);
int light = p.getBrightnessForRender(0);
int lightmapX = light % 65536;
int lightmapY = light / 65536;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapX, lightmapY);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPushMatrix();
GL11.glScalef(0.5F, 0.5F, 0.5F);
GL11.glRotatef(55, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(180, 0.0F, 1.0F, 0.0F);
GL11.glTranslatef(-0.6F, 2.25F, 1.25F);
Minecraft.getMinecraft().renderEngine.bindTexture(getTexture(s));
saya.render(0.0625F);
GL11.glPopMatrix();
if (p.getHeldItem() == null || p.getHeldItem() != s)
{
GL11.glPushMatrix();
GL11.glScalef(0.5F, 0.5F, 0.5F);
@@ -317,30 +373,12 @@ public class ItemKatana extends Item implements IWarpingGear, IRepairable
GL11.glTranslatef(-0.6F, 2.25F, 1.25F);
Minecraft.getMinecraft().renderEngine.bindTexture(getTexture(s));
saya.render(0.0625F);
katana.render(0.0625F);
GL11.glPopMatrix();
if (p.getHeldItem() == null || p.getHeldItem() != s)
{
GL11.glPushMatrix();
GL11.glScalef(0.5F, 0.5F, 0.5F);
GL11.glRotatef(55, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(180, 0.0F, 1.0F, 0.0F);
GL11.glTranslatef(-0.6F, 2.25F, 1.25F);
Minecraft.getMinecraft().renderEngine.bindTexture(getTexture(s));
katana.render(0.0625F);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
break;
}
GL11.glPopMatrix();
}
}
@@ -11,7 +11,8 @@ public class PacketHandler
public static void init ()
{
int i = 0;
INSTANCE.registerMessage(PacketKatanaAttack.class, PacketKatanaAttack.class, i++, Side.SERVER);
int idx = 0;
INSTANCE.registerMessage(PacketKatanaAttack.class, PacketKatanaAttack.class, idx++, Side.SERVER);
INSTANCE.registerMessage(PacketSyncInv.class, PacketSyncInv.class, idx++, Side.CLIENT);
}
}
@@ -0,0 +1,76 @@
package taintedmagic.common.network;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.world.World;
import taintedmagic.common.TaintedMagic;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public class PacketSyncInv implements IMessage, IMessageHandler<PacketSyncInv, IMessage>
{
int playerID;
ItemStack[] inv = null;
public PacketSyncInv ()
{
}
public PacketSyncInv (EntityPlayer p)
{
this.playerID = p.getEntityId();
this.inv = p.inventory.mainInventory;
}
@Override
public IMessage onMessage (PacketSyncInv message, MessageContext ctx)
{
World w = TaintedMagic.proxy.getClientWorld();
if (w == null) return null;
Entity p = w.getEntityByID(message.playerID);
if (p != null && p instanceof EntityPlayer) ((EntityPlayer) p).inventory.mainInventory = message.inv;
return null;
}
@Override
public void fromBytes (ByteBuf buf)
{
playerID = buf.readInt();
PacketBuffer pb = new PacketBuffer(buf);
try
{
ItemStack[] s = new ItemStack[36];
for (int i = 0; i < 36; i++)
s[i] = pb.readItemStackFromBuffer();
inv = s;
}
catch (IOException e)
{
}
}
@Override
public void toBytes (ByteBuf buf)
{
buf.writeInt(playerID);
PacketBuffer pb = new PacketBuffer(buf);
try
{
for (int i = 0; i < 36; i++)
pb.writeItemStackToBuffer(inv[i]);
}
catch (IOException e)
{
}
}
}