Added a config option to disable trail visibility for the local player if they themselves have a trail
This commit is contained in:
parent
f188396c99
commit
7eed85f66b
5 changed files with 60 additions and 10 deletions
|
@ -10,8 +10,13 @@ package biomesoplenty.common.config;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import biomesoplenty.common.remote.TrailManager;
|
||||
import biomesoplenty.common.remote.TrailManager.TrailVisibilityMode;
|
||||
import biomesoplenty.common.util.entity.PlayerUtil;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
public class MiscConfigurationHandler
|
||||
{
|
||||
|
@ -19,6 +24,9 @@ public class MiscConfigurationHandler
|
|||
|
||||
public static boolean useBoPWorldTypeDefault;
|
||||
public static boolean overrideTitlePanorama;
|
||||
|
||||
//Client-side only
|
||||
public static TrailVisibilityMode trailVisbilityMode;
|
||||
|
||||
public static void init(File configFile)
|
||||
{
|
||||
|
@ -31,6 +39,16 @@ public class MiscConfigurationHandler
|
|||
//TODO: Make this default to true once all biomes have been implemented
|
||||
useBoPWorldTypeDefault = config.getBoolean("Default to BoP World Type", "GUI Settings", false, "Use the Biomes O' Plenty World Type by default when selecting a world.");
|
||||
overrideTitlePanorama = config.getBoolean("Enable Biomes O\' Plenty Main Menu Panorama", "GUI Settings", true, "Override the main menu panorama and use ours instead (It\'s nicer!)");
|
||||
|
||||
//Client-side only options
|
||||
if (FMLCommonHandler.instance().getSide() == Side.CLIENT)
|
||||
{
|
||||
//Check if the player has a trail
|
||||
if (TrailManager.trailsMap.containsKey(PlayerUtil.getClientPlayerUUID()))
|
||||
{
|
||||
trailVisbilityMode = TrailVisibilityMode.values()[config.getInt("Modify Trail Visibility", "Trail Settings", 0, 0, 1, "0 = All trails visble, 1 = Others can see your trail but you can'")];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -9,8 +9,11 @@
|
|||
package biomesoplenty.common.handler;
|
||||
|
||||
import biomesoplenty.api.particle.BOPParticleTypes;
|
||||
import biomesoplenty.common.config.MiscConfigurationHandler;
|
||||
import biomesoplenty.common.remote.TrailManager;
|
||||
import biomesoplenty.common.remote.TrailManager.TrailVisibilityMode;
|
||||
import biomesoplenty.core.BiomesOPlenty;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
@ -25,35 +28,39 @@ 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)
|
||||
{
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
EntityPlayer player = (EntityPlayer)event.player;
|
||||
|
||||
//Check if the player has a trail
|
||||
if (TrailManager.trailsMap.containsKey(player.getUniqueID()))
|
||||
{
|
||||
//Don't display if the local player's trail if they have the visibility set to others
|
||||
if (MiscConfigurationHandler.trailVisbilityMode == TrailVisibilityMode.OTHERS && minecraft.thePlayer.getUniqueID() == player.getUniqueID())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String trailName = TrailManager.trailsMap.get(player.getUniqueID());
|
||||
|
||||
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
|
||||
//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;
|
||||
|
||||
BlockPos groundPos = playerPos.add(offsetX, -1, offsetZ);
|
||||
|
||||
if (!world.isAirBlock(groundPos) && world.getBlockState(groundPos).getBlock().isSideSolid(world, groundPos, 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;
|
||||
|
||||
//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);
|
||||
}
|
||||
|
|
|
@ -55,4 +55,9 @@ public class TrailManager
|
|||
BiomesOPlenty.logger.warn("There was an issue retrieving trail info from remote!");
|
||||
}
|
||||
}
|
||||
|
||||
public static enum TrailVisibilityMode
|
||||
{
|
||||
ALL, OTHERS, NOBODY; //TODO: Implement NOBODY mode
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package biomesoplenty.common.util.entity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class PlayerUtil
|
||||
{
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static UUID getClientPlayerUUID()
|
||||
{
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
|
||||
return minecraft.getSession().getProfile().getId();
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import biomesoplenty.common.init.ModGenerators;
|
|||
import biomesoplenty.common.init.ModHandlers;
|
||||
import biomesoplenty.common.init.ModItems;
|
||||
import biomesoplenty.common.init.ModPotions;
|
||||
import biomesoplenty.common.remote.TrailManager;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
|
@ -54,6 +55,7 @@ public class BiomesOPlenty
|
|||
{
|
||||
configDirectory = new File(event.getModConfigurationDirectory(), "biomesoplenty");
|
||||
|
||||
TrailManager.retrieveTrails();
|
||||
ModConfiguration.init(configDirectory);
|
||||
|
||||
// setup blocks before items, because some items need to reference blocks in their constructors (eg seeds)
|
||||
|
|
Loading…
Reference in a new issue