Remove custom fake player in favor of vanilla one, stopped using fake player for worldgen.

This commit is contained in:
Ellpeck 2016-06-19 20:24:13 +02:00
parent 9c16eef80e
commit 144e8e4d0a
5 changed files with 10 additions and 56 deletions

View file

@ -42,7 +42,6 @@ import de.ellpeck.actuallyadditions.mod.recipe.HairyBallHandler;
import de.ellpeck.actuallyadditions.mod.recipe.TreasureChestHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
import de.ellpeck.actuallyadditions.mod.util.FakePlayerUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Mod;
@ -130,7 +129,6 @@ public class ActuallyAdditions{
proxy.postInit(event);
ModUtil.LOGGER.info("PostInitialization Finished.");
FakePlayerUtil.info();
}
@EventHandler

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.data.WorldData;
import de.ellpeck.actuallyadditions.mod.util.FakePlayerUtil;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -25,7 +24,6 @@ public class WorldLoadingEvents{
@SubscribeEvent
public void onUnload(WorldEvent.Unload event){
WorldData.unload(event.getWorld());
FakePlayerUtil.unloadFakePlayer();
}
@SubscribeEvent

View file

@ -60,12 +60,13 @@ public class WorldGenLushCaves extends WorldGenerator{
if(!possiblePoses.isEmpty()){
for(int i = 0; i <= amount; i++){
Collections.shuffle(possiblePoses);
BlockPos pos = possiblePoses.get(0);
if(rand.nextBoolean()){
WorldGenAbstractTree trees = rand.nextBoolean() ? (rand.nextBoolean() ? new WorldGenBigTree(false) : new WorldGenShrub(Blocks.LOG.getDefaultState(), Blocks.LEAVES.getDefaultState())) : new WorldGenTrees(false);
trees.generate(world, rand, possiblePoses.get(0).up());
trees.generate(world, rand, pos.up());
}
else{
ItemDye.applyBonemeal(new ItemStack(Items.DYE, 1, EnumDyeColor.WHITE.getDyeDamage()), world, possiblePoses.get(0));
Blocks.GRASS.grow(world, rand, pos, world.getBlockState(pos));
}
}
}

View file

@ -1,46 +0,0 @@
/*
* This file ("FakePlayerUtil.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.util;
import com.mojang.authlib.GameProfile;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import java.util.UUID;
public final class FakePlayerUtil{
private static final String FAKE_NAME = ModUtil.MOD_ID+"fakeplayer";
private static final GameProfile FAKE_PROFILE = new GameProfile(UUID.nameUUIDFromBytes(FAKE_NAME.getBytes()), FAKE_NAME);
private static FakePlayer theFakePlayer;
public static void info(){
ModUtil.LOGGER.info(ModUtil.NAME+"' Fake Player: '"+FAKE_PROFILE.getName()+"', UUID: "+FAKE_PROFILE.getId());
}
public static FakePlayer getFakePlayer(World world){
if(world instanceof WorldServer){
if(theFakePlayer == null){
theFakePlayer = FakePlayerFactory.get((WorldServer)world, FAKE_PROFILE);
}
return theFakePlayer;
}
else{
return null;
}
}
public static void unloadFakePlayer(){
theFakePlayer = null;
}
}

View file

@ -41,6 +41,8 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
@ -167,7 +169,6 @@ public final class WorldUtil{
//Fluids
if(replaceable && !(block instanceof IFluidBlock) && !(block instanceof BlockLiquid)){
FluidStack fluid = null;
//TODO Remove when FluidContainerRegistry is gone
if(FluidContainerRegistry.isFilledContainer(stack)){
fluid = FluidContainerRegistry.getFluidForFilledItem(stack);
}
@ -201,9 +202,11 @@ public final class WorldUtil{
//Everything else
try{
EntityPlayer fake = FakePlayerUtil.getFakePlayer(world);
stack.onItemUse(fake, world, offsetPos, fake.getActiveHand(), side.getOpposite(), 0.5F, 0.5F, 0.5F);
return stack;
if(world instanceof WorldServer){
FakePlayer fake = FakePlayerFactory.getMinecraft((WorldServer)world);
stack.onItemUse(fake, world, offsetPos, fake.getActiveHand(), side.getOpposite(), 0.5F, 0.5F, 0.5F);
return stack;
}
}
catch(Exception e){
ModUtil.LOGGER.error("Something that places Blocks at "+offsetPos.getX()+", "+offsetPos.getY()+", "+offsetPos.getZ()+" in World "+world.provider.getDimension()+" threw an Exception! Don't let that happen again!", e);