Trails now work properly - There's still some extra features to be added, however they do work quite nicely

This commit is contained in:
Adubbz 2015-10-11 13:23:47 +11:00
parent 0167c14972
commit b219317e92
8 changed files with 91 additions and 75 deletions

View file

@ -17,27 +17,27 @@ import net.minecraftforge.fml.client.FMLClientHandler;
public class EntityTrailFX extends EntityFX public class EntityTrailFX extends EntityFX
{ {
private static ResourceLocation TEST_TRAIL_LOC = new ResourceLocation("biomesoplenty:textures/particles/test_trail.png"); private ResourceLocation trailResource;
/**The index of the flower to be spawned, values are 0-3*/ /**The index of the flower to be spawned, values are 0-3*/
private int particleIndex; private int particleIndex;
private double startY;
public EntityTrailFX(World world, double x, double y, double z) public EntityTrailFX(World world, double x, double y, double z, String trailName)
{ {
super(world, x, y, z); super(world, x, y, z);
this.trailResource = new ResourceLocation("biomesoplenty:textures/particles/" + trailName + ".png");
this.motionX = this.motionY = this.motionZ = 0.0D; //Trail particles should not move this.motionX = this.motionY = this.motionZ = 0.0D; //Trail particles should not move
this.particleMaxAge = 550; this.particleMaxAge = 550;
this.particleIndex = this.rand.nextInt(4); //Choose a random index on creation this.particleIndex = this.rand.nextInt(4); //Choose a random index on creation
this.startY = y; //Where y coordinate where this particle has started (before it moves downwards with time)
} }
@Override @Override
public void renderParticle(WorldRenderer renderer, Entity entity, float partialTicks, float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY) public void renderParticle(WorldRenderer renderer, Entity entity, float partialTicks, float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY)
{ {
// EffectRenderer will by default bind the vanilla particles texture, override with our own // EffectRenderer will by default bind the vanilla particles texture, override with our own
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEST_TRAIL_LOC); FMLClientHandler.instance().getClient().renderEngine.bindTexture(this.trailResource);
particleIndex = 1;
//The overall maxU and maxV of the particle sheet is 1.0 (representing 16px) //The overall maxU and maxV of the particle sheet is 1.0 (representing 16px)
float minU = (particleIndex % 2) * 0.5F; //Particles on the left side are 0, right are 0.5 float minU = (particleIndex % 2) * 0.5F; //Particles on the left side are 0, right are 0.5
@ -65,4 +65,13 @@ public class EntityTrailFX extends EntityFX
{ {
return 2; return 2;
} }
@Override
public void onUpdate()
{
super.onUpdate();
this.posY = this.startY - 0.01 * ((float)this.particleAge / (float)this.particleMaxAge);
this.prevPosY = this.posY;
}
} }

View file

@ -8,7 +8,9 @@
package biomesoplenty.common.handler; package biomesoplenty.common.handler;
import biomesoplenty.api.particle.BOPParticleTypes;
import biomesoplenty.common.remote.TrailManager; import biomesoplenty.common.remote.TrailManager;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos; import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -34,6 +36,12 @@ public class TrailsEventHandler
if (event.phase == TickEvent.Phase.START) if (event.phase == TickEvent.Phase.START)
{ {
EntityPlayer player = (EntityPlayer)event.player; EntityPlayer player = (EntityPlayer)event.player;
//Check if the player has a trail
if (TrailManager.trailsMap.containsKey(player.getUniqueID()))
{
String trailName = TrailManager.trailsMap.get(player.getUniqueID());
World world = player.worldObj; World world = player.worldObj;
float groundYOffset = 0.015625F; //Prevents particles from z-fighting with the ground float groundYOffset = 0.015625F; //Prevents particles from z-fighting with the ground
BlockPos playerPos = player.getPosition(); BlockPos playerPos = player.getPosition();
@ -46,7 +54,9 @@ public class TrailsEventHandler
double offsetX = 0.3 - world.rand.nextFloat() * 0.6; double offsetX = 0.3 - world.rand.nextFloat() * 0.6;
double offsetZ = 0.3 - world.rand.nextFloat() * 0.6; double offsetZ = 0.3 - world.rand.nextFloat() * 0.6;
//BiomesOPlenty.proxy.spawnParticle(BOPParticleTypes.PLAYER_TRAIL, player.posX + offsetX, ((int)player.posY) + groundYOffset, player.posZ + offsetZ); //Move the particle up by 0.01 on spawn to prevent z-fighting (the trail particles move down with time)
BiomesOPlenty.proxy.spawnParticle(BOPParticleTypes.PLAYER_TRAIL, player.posX + offsetX, ((int)player.posY) + groundYOffset + 0.01, player.posZ + offsetZ, trailName);
}
} }
} }
} }

View file

@ -9,14 +9,13 @@
package biomesoplenty.common.remote; package biomesoplenty.common.remote;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class TrailManager public class TrailManager
@ -25,18 +24,10 @@ public class TrailManager
//private static File cacheDirectory = new File(Minecraft.getMinecraft().fil) //private static File cacheDirectory = new File(Minecraft.getMinecraft().fil)
private static HashMap<UUID, String> trailsMap = new HashMap<UUID, String>(); public static HashMap<UUID, String> trailsMap = new HashMap<UUID, String>();
private static HashMap<String, ResourceLocation> trailTextures = new HashMap<String, ResourceLocation>(); public static HashMap<String, ResourceLocation> trailTextures = new HashMap<String, ResourceLocation>();
public static void retrieveTrails() public static void retrieveTrails()
{
new TrailChecker().start();
}
private static class TrailChecker extends Thread
{
@Override
public void run()
{ {
try try
{ {
@ -61,20 +52,15 @@ public class TrailManager
reader.close(); reader.close();
//Retrieve trail textures //TODO: Retrieve trail textures
for (String trailName : trailTextures.keySet()) for (String trailName : trailTextures.keySet())
{ {
} }
} }
catch (MalformedURLException e) catch (Exception e)
{ {
e.printStackTrace(); BiomesOPlenty.logger.warn("There was an issue retrieving trails from remote!");
}
catch (IOException e)
{
e.printStackTrace();
}
} }
} }
} }

View file

@ -8,6 +8,21 @@
package biomesoplenty.core; package biomesoplenty.core;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.api.particle.BOPParticleTypes;
import biomesoplenty.client.particle.EntityDandelionFX;
import biomesoplenty.client.particle.EntityPixieTrailFX;
import biomesoplenty.client.particle.EntityTrailFX;
import biomesoplenty.common.config.MiscConfigurationHandler;
import biomesoplenty.common.entities.EntityPixie;
import biomesoplenty.common.entities.EntityWasp;
import biomesoplenty.common.entities.RenderPixie;
import biomesoplenty.common.entities.RenderWasp;
import biomesoplenty.common.entities.projectiles.EntityDart;
import biomesoplenty.common.entities.projectiles.EntityMudball;
import biomesoplenty.common.entities.projectiles.RenderDart;
import biomesoplenty.common.entities.projectiles.RenderMudball;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -27,13 +42,6 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.api.particle.BOPParticleTypes;
import biomesoplenty.client.particle.*;
import biomesoplenty.common.config.MiscConfigurationHandler;
import biomesoplenty.common.entities.*;
import biomesoplenty.common.entities.projectiles.*;
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
{ {
@ -104,7 +112,7 @@ public class ClientProxy extends CommonProxy
} }
@Override @Override
public void spawnParticle(BOPParticleTypes type, double x, double y, double z) public void spawnParticle(BOPParticleTypes type, double x, double y, double z, Object... info)
{ {
Minecraft minecraft = Minecraft.getMinecraft(); Minecraft minecraft = Minecraft.getMinecraft();
EntityFX entityFx = null; EntityFX entityFx = null;
@ -121,7 +129,10 @@ public class ClientProxy extends CommonProxy
minecraft.theWorld.spawnParticle(EnumParticleTypes.ITEM_CRACK, x, y, z, MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), new int[] {itemId}); minecraft.theWorld.spawnParticle(EnumParticleTypes.ITEM_CRACK, x, y, z, MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), new int[] {itemId});
return; return;
case PLAYER_TRAIL: case PLAYER_TRAIL:
entityFx = new EntityTrailFX(minecraft.theWorld, x, y, z); if (info.length < 1)
throw new RuntimeException("Missing argument for trail name!");
entityFx = new EntityTrailFX(minecraft.theWorld, x, y, z, (String)info[0]);
break; break;
default: default:
break; break;

View file

@ -18,5 +18,5 @@ public class CommonProxy
public void registerItemVariantModel(Item item, String name, int metadata) {} public void registerItemVariantModel(Item item, String name, int metadata) {}
public void registerNonRenderingProperties(Block block) {} public void registerNonRenderingProperties(Block block) {}
public void registerFluidBlockRendering(Block block, String name) {} public void registerFluidBlockRendering(Block block, String name) {}
public void spawnParticle(BOPParticleTypes type, double x, double y, double z) {} public void spawnParticle(BOPParticleTypes type, double x, double y, double z, Object... info) {}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B