Began work on trails

This commit is contained in:
Adubbz 2015-09-19 17:05:06 +10:00
parent c5d36e732d
commit e68102d047
7 changed files with 225 additions and 1 deletions

View File

@ -2,5 +2,5 @@ package biomesoplenty.api.particle;
public enum BOPParticleTypes
{
PIXIETRAIL, DANDELION, MUD;
PIXIETRAIL, DANDELION, MUD, PLAYER_TRAIL;
}

View File

@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright 2014, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.client.particle;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
public class EntityTrailFX extends EntityFX
{
private static ResourceLocation TEST_TRAIL_LOC = new ResourceLocation("biomesoplenty:textures/particles/test_trail.png");
/**The index of the flower to be spawned, values are 0-3*/
private int particleIndex;
public EntityTrailFX(World world, double x, double y, double z)
{
super(world, x, y, z);
this.motionX = this.motionY = this.motionZ = 0.0D; //Trail particles should not move
this.particleMaxAge = 550;
this.particleIndex = this.rand.nextInt(4); //Choose a random index on creation
}
@Override
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
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEST_TRAIL_LOC);
particleIndex = 1;
//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 maxU = minU + 0.5F; //Each flower is 8px wide (half of the overall sheet)
float minV = (particleIndex / 2) * 0.5F; //Uses integer rounding errors (0 and 1 = 0, 2 and 3 = 1)
float maxV = minV + 0.5F; //Each flower is 8px high (half of the overall sheet)
//Vanilla particle rendering
float alpha = 1.0F - Math.min(1.0F, 2.0F * this.particleAge / this.particleMaxAge);
float width = 0.15F;
float x = (float)(prevPosX + (posX - prevPosX) - interpPosX);
float y = (float)(prevPosY + (posY - prevPosY) - interpPosY);
float z = (float)(prevPosZ + (posZ - prevPosZ) - interpPosZ);
renderer.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, alpha);
renderer.addVertexWithUV(x - width, y, z + width, minU, maxV);
renderer.addVertexWithUV(x + width, y, z + width, minU, minV);
renderer.addVertexWithUV(x + width, y, z - width, maxU, minV);
renderer.addVertexWithUV(x - width, y, z - width, maxU, maxV);
}
@Override
public int getFXLayer()
{
return 2;
}
}

View File

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright 2014, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.handler;
import biomesoplenty.api.particle.BOPParticleTypes;
import biomesoplenty.common.remote.TrailManager;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class TrailsEventHandler
{
static
{
TrailManager.retrieveTrails();
}
@SubscribeEvent(receiveCanceled = true)
public void onEntityUpdate(PlayerTickEvent event)
{
if (event.phase == TickEvent.Phase.START)
{
EntityPlayer player = (EntityPlayer)event.player;
World world = player.worldObj;
float groundYOffset = 0.015625F; //Prevents particles from z-fighting with the ground
BlockPos playerPos = player.getPosition();
if (world.getBlockState(playerPos.down()).getBlock().isSideSolid(world, playerPos.down(), EnumFacing.UP)) //Only place particles on blocks with a solid top
{
if (player.posX != player.prevPosX || player.posZ != player.prevPosZ) //Particles should only spawn if the player is moving
{
//Makes placement more interesting, scatter slightly on the x and z axis
double offsetX = 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);
}
}
}
}
@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event)
{
EntityPlayer player = event.player;
World world = player.worldObj;
if (world.isRemote)
{
//Send client trail preferences
}
else
{
//Server sends other player preferences
}
}
}

View File

@ -44,5 +44,6 @@ public class ModHandlers
{
MinecraftForge.EVENT_BUS.register(new ModelBakeHandler());
MinecraftForge.EVENT_BUS.register(new GuiEventHandler());
FMLCommonHandler.instance().bus().register(new TrailsEventHandler());
}
}

View File

@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright 2014, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.remote;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.UUID;
import net.minecraft.util.ResourceLocation;
public class TrailManager
{
private static final String REMOTE_TRAILS_FILE = "https://raw.githubusercontent.com/Glitchfiend/BiomesOPlenty/master/trails.txt";
//private static File cacheDirectory = new File(Minecraft.getMinecraft().fil)
private static HashMap<UUID, String> trailsMap = new HashMap<UUID, String>();
private static HashMap<String, ResourceLocation> trailTextures = new HashMap<String, ResourceLocation>();
public static void retrieveTrails()
{
new TrailChecker().start();
}
private static class TrailChecker extends Thread
{
@Override
public void run()
{
try
{
URL url = new URL(REMOTE_TRAILS_FILE);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)");
connection.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = reader.readLine()) != null)
{
if (line.startsWith("//") || line.isEmpty()) continue;
String[] split = line.split(":");
trailsMap.put(UUID.fromString(split[0]), split[1]);
if (!trailTextures.containsKey(split[1])) trailTextures.put(split[1], null);
}
reader.close();
//Retrieve trail textures
for (String trailName : trailTextures.keySet())
{
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}

View File

@ -120,6 +120,9 @@ public class ClientProxy extends CommonProxy
int itemId = Item.getIdFromItem(BOPItems.mudball);
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;
case PLAYER_TRAIL:
entityFx = new EntityTrailFX(minecraft.theWorld, x, y, z);
break;
default:
break;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B