mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-26 06:43:01 +00:00
- Familiars: Rendering forwarded to RenderPrimalOrb from TC until own render is written
- Familiars: Now properly controlled by Server and mirrored to clients.
This commit is contained in:
1 parent
87de735428
commit
95c77249bc
14 files changed
+369
-124
No files matched your search
@@ -3,7 +3,9 @@ package makeo.gadomancy.client;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import makeo.gadomancy.client.events.ClientTickHandler;
|
||||
import makeo.gadomancy.client.events.RenderEventHandler;
|
||||
import makeo.gadomancy.client.events.ResourceReloadListener;
|
||||
import makeo.gadomancy.client.gui.InfusionClawGui;
|
||||
@@ -11,7 +13,7 @@ import makeo.gadomancy.client.renderers.block.BlockExtendedNodeJarRenderer;
|
||||
import makeo.gadomancy.client.renderers.block.RenderBlockTransparent;
|
||||
import makeo.gadomancy.client.renderers.entity.RenderAdditionalGolemBase;
|
||||
import makeo.gadomancy.client.renderers.item.*;
|
||||
import makeo.gadomancy.client.renderers.item.familiar.FamiliarHandlerClient;
|
||||
import makeo.gadomancy.client.util.FamiliarHandlerClient;
|
||||
import makeo.gadomancy.client.renderers.tile.*;
|
||||
import makeo.gadomancy.common.CommonProxy;
|
||||
import makeo.gadomancy.common.blocks.tiles.*;
|
||||
@@ -55,8 +57,6 @@ public class ClientProxy extends CommonProxy {
|
||||
public void initalize() {
|
||||
super.initalize();
|
||||
|
||||
familiarHandler = new FamiliarHandlerClient(); //Overwriting the server sided one.
|
||||
|
||||
injectGolemTextures();
|
||||
|
||||
//Tiles
|
||||
@@ -114,6 +114,8 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new RenderEventHandler());
|
||||
|
||||
FMLCommonHandler.instance().bus().register(new ClientTickHandler());
|
||||
|
||||
super.postInitalize();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package makeo.gadomancy.client.events;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import makeo.gadomancy.client.util.FamiliarHandlerClient;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 01.11.2015 10:41
|
||||
*/
|
||||
public class ClientTickHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
if(event.phase.equals(TickEvent.Phase.END)) {
|
||||
FamiliarHandlerClient.playerTickEvent();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package makeo.gadomancy.client.events;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import makeo.gadomancy.client.util.ExtendedTypeDisplayManager;
|
||||
import makeo.gadomancy.client.util.FamiliarHandlerClient;
|
||||
import makeo.gadomancy.client.util.MultiTickEffectDispatcher;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileExtendedNode;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileExtendedNodeJar;
|
||||
@@ -12,6 +13,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -89,4 +91,9 @@ public class RenderEventHandler {
|
||||
ExtendedTypeDisplayManager.notifyRenderTick();
|
||||
MultiTickEffectDispatcher.notifyRenderTick(Minecraft.getMinecraft().theWorld, event.partialTicks);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerRenderEvent(RenderPlayerEvent.Post renderEvent) {
|
||||
FamiliarHandlerClient.playerRenderEvent(renderEvent.entityPlayer, renderEvent.partialRenderTick);
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package makeo.gadomancy.client.renderers.item.familiar;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import makeo.gadomancy.common.familiar.FamiliarHandlerServer;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 31.10.2015 12:13
|
||||
*/
|
||||
public class FamiliarHandlerClient extends FamiliarHandlerServer {
|
||||
|
||||
//TODO has to handle rendering and processing of animation packets.
|
||||
|
||||
@Override
|
||||
public void setupPostInit() {
|
||||
super.setupPostInit();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyEquip(World world, ItemStack familiarStack, EntityPlayer player) {
|
||||
super.notifyEquip(world, familiarStack, player);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyUnequip(World world, ItemStack familiarStack, EntityPlayer player) {
|
||||
super.notifyUnequip(world, familiarStack, player);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equippedTick(World world, ItemStack familiarStack, EntityPlayer player) {
|
||||
super.equippedTick(world, familiarStack, player);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void processPacket(PacketFamiliar packet) {
|
||||
if(packet instanceof PacketFamiliar.PacketFamiliarBolt) {
|
||||
PacketFamiliar.PacketFamiliarBolt pkt = (PacketFamiliar.PacketFamiliarBolt) packet;
|
||||
EntityPlayer p = Minecraft.getMinecraft().thePlayer;
|
||||
Thaumcraft.proxy.nodeBolt(Minecraft.getMinecraft().theWorld, (float) p.posX, (float) (p.posY + p.eyeHeight), (float) p.posZ, pkt.targetX, pkt.targetY, pkt.targetZ);
|
||||
//TODO zap given coordinates from current familiar render coordinates
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package makeo.gadomancy.client.util;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.client.renderers.entity.RenderPrimalOrb;
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 31.10.2015 12:13
|
||||
*/
|
||||
public class FamiliarHandlerClient {
|
||||
|
||||
private static RenderPrimalOrb fallbackRenderer;
|
||||
|
||||
private static Map<String, PartialEntityFamiliar> clientFamiliars = new HashMap<String, PartialEntityFamiliar>();
|
||||
private static List<String> familiarPlayers = new ArrayList<String>();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void processPacket(PacketFamiliar packet) {
|
||||
if(packet instanceof PacketFamiliar.PacketFamiliarBolt) {
|
||||
PacketFamiliar.PacketFamiliarBolt pkt = (PacketFamiliar.PacketFamiliarBolt) packet;
|
||||
EntityPlayer p = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(pkt.owner);
|
||||
if(p == null || p.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) > 1024) return; //32^2
|
||||
PartialEntityFamiliar fam = clientFamiliars.get(p.getCommandSenderName());
|
||||
if(fam == null) return;
|
||||
Thaumcraft.proxy.nodeBolt(Minecraft.getMinecraft().theWorld, (float) fam.posX, (float) fam.posY, (float) fam.posZ, pkt.targetX, pkt.targetY, pkt.targetZ);
|
||||
//TODO zap given coordinates from current familiar render coordinates
|
||||
} else if(packet instanceof PacketFamiliar.PacketFamiliarSyncCompletely) {
|
||||
PacketFamiliar.PacketFamiliarSyncCompletely sync = (PacketFamiliar.PacketFamiliarSyncCompletely) packet;
|
||||
familiarPlayers = sync.playerNamesWithFamiliars;
|
||||
} else if(packet instanceof PacketFamiliar.PacketFamiliarSyncSingle) {
|
||||
PacketFamiliar.PacketFamiliarSyncSingle sync = (PacketFamiliar.PacketFamiliarSyncSingle) packet;
|
||||
String value = sync.name;
|
||||
if(sync.status) {
|
||||
if(!familiarPlayers.contains(value)) {
|
||||
familiarPlayers.add(value);
|
||||
clientFamiliars.put(value, new PartialEntityFamiliar(Minecraft.getMinecraft().theWorld.getPlayerEntityByName(value), value));
|
||||
}
|
||||
} else {
|
||||
clientFamiliars.remove(value);
|
||||
familiarPlayers.remove(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void playerRenderEvent(EntityPlayer player, float partialTicks) { //RenderPlayerEvent.Post
|
||||
EntityLivingBase renderView = Minecraft.getMinecraft().renderViewEntity;
|
||||
for(String ownerName : clientFamiliars.keySet()) {
|
||||
PartialEntityFamiliar fam = clientFamiliars.get(ownerName);
|
||||
|
||||
if(!ownerName.equals(player.getCommandSenderName())) continue;
|
||||
if(renderView.worldObj.provider.dimensionId != player.worldObj.provider.dimensionId) continue;
|
||||
if(renderView.getDistanceSqToEntity(player) > 1024) continue;
|
||||
|
||||
fallbackRenderer.renderEntityAt(fam.dummyEntity, fam.renderX, fam.renderY, fam.renderZ, 0, partialTicks);
|
||||
//Render at abs positions: ram.posX, fam.posY, fam.posZ
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void playerTickEvent() {
|
||||
for(PartialEntityFamiliar fam : clientFamiliars.values()) fam.tick();
|
||||
}
|
||||
|
||||
static {
|
||||
fallbackRenderer = new RenderPrimalOrb();
|
||||
fallbackRenderer.setRenderManager(RenderManager.instance);
|
||||
}
|
||||
|
||||
public static class DummyEntityFamiliar extends Entity {
|
||||
|
||||
public DummyEntityFamiliar(World p_i1582_1_) {
|
||||
super(p_i1582_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static class PartialEntityFamiliar {
|
||||
|
||||
private static final double RAD_CAP = 2 * Math.PI;
|
||||
private static final int CRICLE_TIME_TICKS = 160;
|
||||
private static final double RADIUS = 1;
|
||||
|
||||
public DummyEntityFamiliar dummyEntity = new DummyEntityFamiliar(null);
|
||||
public WeakReference<EntityPlayer> owner;
|
||||
public String potentialOwnerName;
|
||||
public double posX, posY, posZ;
|
||||
public double renderX, renderY, renderZ;
|
||||
public double prevPosX, prevPosY, prevPosZ;
|
||||
public int ticksExisted = 0;
|
||||
|
||||
public PartialEntityFamiliar(EntityPlayer owner, String ownerNameToSearch) {
|
||||
this.owner = new WeakReference<EntityPlayer>(owner);
|
||||
this.potentialOwnerName = ownerNameToSearch;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
ticksExisted++;
|
||||
dummyEntity.ticksExisted = ticksExisted;
|
||||
|
||||
if(owner.get() == null) {
|
||||
if(potentialOwnerName != null) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(potentialOwnerName);
|
||||
if(player != null) {
|
||||
owner = new WeakReference<EntityPlayer>(player);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(owner.get().worldObj.provider.dimensionId != Minecraft.getMinecraft().renderViewEntity.worldObj.provider.dimensionId) {
|
||||
owner = new WeakReference<EntityPlayer>(null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.prevPosX = this.posX;
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
|
||||
double part = ((double) ticksExisted) / ((double) CRICLE_TIME_TICKS);
|
||||
double theta = RAD_CAP * part;
|
||||
this.renderX = RADIUS * Math.cos(theta);
|
||||
this.renderZ = RADIUS * Math.sin(theta);
|
||||
this.renderY = 1 + Math.sin(theta * 2) / 4D;
|
||||
|
||||
this.posX = owner.get().posX + renderX;
|
||||
this.posZ = owner.get().posZ + renderZ;
|
||||
this.posY = owner.get().posY + renderY;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user