Skip to content

Commit

Permalink
Simplify spectral human
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jul 19, 2024
1 parent efa9c8a commit d123611
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import mod.emt.harkenscythe.entity.HSEntitySpectralHuman;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderBiped;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand All @@ -20,13 +17,6 @@ public HSRendererEntitySpectralHuman(RenderManager renderManager)
super(renderManager, new ModelPlayer(0.0F, false), 0.5F);
}

@Override
protected ResourceLocation getEntityTexture(HSEntitySpectralHuman entity)
{
NetworkPlayerInfo networkPlayerInfo = entity.getNetworkPlayerInfo();
return networkPlayerInfo == null ? DefaultPlayerSkin.getDefaultSkin(entity.getUniqueID()) : networkPlayerInfo.getLocationSkin();
}

public static class Factory implements IRenderFactory<HSEntitySpectralHuman>
{
@Override
Expand Down
47 changes: 2 additions & 45 deletions src/main/java/mod/emt/harkenscythe/entity/HSEntitySoul.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package mod.emt.harkenscythe.entity;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import com.mojang.authlib.GameProfile;
import io.netty.buffer.ByteBuf;
import mod.emt.harkenscythe.event.HSEventLivingDeath;
import mod.emt.harkenscythe.init.HSItems;
Expand All @@ -22,13 +20,11 @@
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;

public class HSEntitySoul extends HSEntityEssence implements IEntityAdditionalSpawnData
{
private EntityLivingBase originalEntity;
private GameProfile playerGameProfile;
private int soulType;

public HSEntitySoul(World world)
Expand All @@ -45,10 +41,6 @@ public HSEntitySoul(World world, EntityLivingBase entity)
this.setSize(1.2F, 1.2F);
this.setOriginalEntity(entity);
this.setSoulType(entity);
if (entity instanceof EntityPlayer)
{
this.setPlayerGameProfile(((EntityPlayer) entity).getGameProfile());
}
}

public EntityLivingBase getOriginalEntity()
Expand All @@ -61,16 +53,6 @@ public void setOriginalEntity(EntityLivingBase originalEntity)
this.originalEntity = originalEntity;
}

public GameProfile getPlayerGameProfile()
{
return this.playerGameProfile;
}

public void setPlayerGameProfile(GameProfile playerGameProfile)
{
this.playerGameProfile = playerGameProfile;
}

public int getSoulType()
{
return this.soulType;
Expand Down Expand Up @@ -177,16 +159,8 @@ public void writeEntityToNBT(NBTTagCompound compound)
{
NBTTagCompound originalEntityNBT = new NBTTagCompound();
this.getOriginalEntity().writeToNBT(originalEntityNBT);
if (this.getOriginalEntity() instanceof EntityPlayer)
{
originalEntityNBT.setString("id", ((EntityPlayer) this.getOriginalEntity()).getGameProfile().getId().toString());
originalEntityNBT.setString("name", ((EntityPlayer) this.getOriginalEntity()).getGameProfile().getName());
}
else
{
originalEntityNBT.setString("id", EntityList.getKey(this.getOriginalEntity().getClass()).toString());
originalEntityNBT.setString("name", this.getOriginalEntity().getName());
}
originalEntityNBT.setString("id", EntityList.getKey(this.getOriginalEntity().getClass()).toString());
originalEntityNBT.setString("name", this.getOriginalEntity().getName());
compound.setTag("OriginalEntity", originalEntityNBT);
}
}
Expand All @@ -201,36 +175,19 @@ public void readEntityFromNBT(NBTTagCompound compound)
NBTTagCompound originalEntityNBT = compound.getCompoundTag("OriginalEntity");
Entity entityFromNBT = EntityList.createEntityFromNBT(originalEntityNBT, this.world);
if (entityFromNBT instanceof EntityLivingBase) this.setOriginalEntity((EntityLivingBase) entityFromNBT);
if (entityFromNBT instanceof EntityPlayer)
{
UUID uuid = UUID.fromString(originalEntityNBT.getString("id"));
String name = originalEntityNBT.getString("name");
this.setPlayerGameProfile(new GameProfile(uuid, name));
}
}
}

@Override
public void writeSpawnData(ByteBuf data)
{
data.writeInt(this.getSoulType());
if (this.getOriginalEntity() instanceof EntityPlayer)
{
ByteBufUtils.writeUTF8String(data, ((EntityPlayer) this.getOriginalEntity()).getGameProfile().getId().toString());
ByteBufUtils.writeUTF8String(data, ((EntityPlayer) this.getOriginalEntity()).getGameProfile().getName());
}
}

@Override
public void readSpawnData(ByteBuf data)
{
this.setSoulType(data.readInt());
if (this.getPlayerGameProfile() != null)
{
UUID uuid = UUID.fromString(ByteBufUtils.readUTF8String(data));
String name = ByteBufUtils.readUTF8String(data);
this.setPlayerGameProfile(new GameProfile(uuid, name));
}
}

private ItemStack getRandomDamagedLivingmetalEquipment(EntityPlayer player)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package mod.emt.harkenscythe.entity;

import java.util.UUID;
import com.mojang.authlib.GameProfile;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAILookIdle;
Expand All @@ -14,73 +10,14 @@
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;

public class HSEntitySpectralHuman extends EntityMob implements IEntityAdditionalSpawnData
public class HSEntitySpectralHuman extends EntityMob
{
private GameProfile playerGameProfile;
private NetworkPlayerInfo networkPlayerInfo;

public HSEntitySpectralHuman(World world)
{
super(world);
this.setSize(0.6F, 1.95F);
this.setCustomNameTag("Spectral Human");
}

public HSEntitySpectralHuman(World world, GameProfile playerGameProfile)
{
super(world);
this.setSize(0.6F, 1.95F);
this.setCustomNameTag("Spectral " + playerGameProfile.getName());
this.setPlayerGameProfile(playerGameProfile);
this.setNetworkPlayerInfo(new NetworkPlayerInfo(playerGameProfile));
}

public GameProfile getPlayerGameProfile()
{
return this.playerGameProfile;
}

public void setPlayerGameProfile(GameProfile playerGameProfile)
{
this.playerGameProfile = playerGameProfile;
}

public NetworkPlayerInfo getNetworkPlayerInfo()
{
return this.networkPlayerInfo;
}

public void setNetworkPlayerInfo(NetworkPlayerInfo networkPlayerInfo)
{
this.networkPlayerInfo = networkPlayerInfo;
}

@Override
public void writeSpawnData(ByteBuf data)
{
if (this.getPlayerGameProfile() != null)
{
ByteBufUtils.writeUTF8String(data, this.getPlayerGameProfile().getId().toString());
ByteBufUtils.writeUTF8String(data, this.getPlayerGameProfile().getName());
}
}

@Override
public void readSpawnData(ByteBuf data)
{
if (this.getPlayerGameProfile() != null)
{
UUID uuid = UUID.fromString(ByteBufUtils.readUTF8String(data));
String name = ByteBufUtils.readUTF8String(data);
this.setPlayerGameProfile(new GameProfile(uuid, name));
this.setNetworkPlayerInfo(new NetworkPlayerInfo(this.getPlayerGameProfile()));
}
}

@Override
Expand All @@ -95,27 +32,6 @@ protected void initEntityAI()
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget<>(this, EntityPlayer.class, true));
}

@Override
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
NBTTagCompound tagCompound = new NBTTagCompound();
NBTUtil.writeGameProfile(tagCompound, this.getPlayerGameProfile());
compound.setTag("OriginalPlayer", tagCompound);
}

@Override
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
if (compound.hasKey("OriginalPlayer", 10))
{
this.setPlayerGameProfile(NBTUtil.readGameProfileFromNBT(compound.getCompoundTag("OriginalPlayer")));
this.setNetworkPlayerInfo(new NetworkPlayerInfo(this.getPlayerGameProfile()));
this.setCustomNameTag("Spectral " + this.getPlayerGameProfile().getName());
}
}

@Override
protected void applyEntityAttributes()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ else if (entity.getEntityData().getBoolean("IsSpectral"))

public static void spawnSpectralEntity(World world, @Nullable EntityLivingBase entity, BlockPos pos, boolean modifyAI)
{
if (world.isRemote) return;
// Reanimate original entity
if (entity != null && isWhitelistedMob(entity))
{
Expand All @@ -81,7 +80,7 @@ public static void spawnSpectralEntity(World world, @Nullable EntityLivingBase e
// Spawn spectral human
else if (entity instanceof EntityPlayer)
{
entity = new HSEntitySpectralHuman(world, ((EntityPlayer) entity).getGameProfile());
entity = new HSEntitySpectralHuman(world);
}
// Spawn ectoglobin
else
Expand All @@ -93,17 +92,16 @@ else if (entity instanceof EntityPlayer)
{
modifyAI((EntityCreature) entity);
}
world.spawnEntity(entity);
if (!world.isRemote) world.spawnEntity(entity);
world.playSound(null, pos, HSSoundEvents.ESSENCE_SOUL_SUMMON, SoundCategory.NEUTRAL, 1.0F, 1.5F / (world.rand.nextFloat() * 0.4F + 1.2F));
}

private static void spawnSoul(World world, EntityLivingBase entity)
{
if (world.isRemote) return;
if (entity.getEntityData().getBoolean("IsSpectral") || entity instanceof HSEntityGlobin) return;
HSEntitySoul soul = new HSEntitySoul(world, entity);
soul.setPosition(entity.posX, entity.posY, entity.posZ);
world.spawnEntity(soul);
if (!world.isRemote) world.spawnEntity(soul);
world.playSound(null, entity.getPosition(), HSSoundEvents.ESSENCE_SOUL_SPAWN, SoundCategory.NEUTRAL, 1.0F, 1.5F / (world.rand.nextFloat() * 0.4F + 1.2F));
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/mod/emt/harkenscythe/event/HSEventRenderLiving.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mod.emt.harkenscythe.event;

import mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.entity.HSEntitySpectralHuman;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -14,17 +15,21 @@ public class HSEventRenderLiving
public static void onRenderLivingPre(RenderLivingEvent.Pre event)
{
// TODO: Replace with entity data instead of name tags
if (!event.getEntity().getCustomNameTag().startsWith("Spectral")) return;
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
GlStateManager.color(0.5F, 0.5F, 1.0F, 0.5F);
if (event.getEntity().getCustomNameTag().startsWith("Spectral") || event.getEntity() instanceof HSEntitySpectralHuman)
{
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
GlStateManager.color(0.5F, 0.5F, 1.0F, 0.5F);
}
}

@SubscribeEvent
public static void onRenderLivingPost(RenderLivingEvent.Post event)
{
// TODO: Replace with entity data instead of name tags
if (!event.getEntity().getCustomNameTag().startsWith("Spectral")) return;
GlStateManager.disableBlend();
if (event.getEntity().getCustomNameTag().startsWith("Spectral") || event.getEntity() instanceof HSEntitySpectralHuman)
{
GlStateManager.disableBlend();
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/harkenscythe/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ entity.harkenscythe.ectoglobin.name=Ectoglobin
entity.harkenscythe.harbinger.name=Harbinger
entity.harkenscythe.hemoglobin.name=Hemoglobin
entity.harkenscythe.soul.name=Soul Essence
entity.harkenscythe.spectral_human.name=Spectral Human
entity.harkenscythe.spectral_potion.name=Spectral Potion

# ENCHANTMENTS
enchantment.harkenscythe.bloodletting=Bloodletting
Expand Down

0 comments on commit d123611

Please sign in to comment.