From 144e8e4d0a602d0464cde8cc8d9e8b7c59bab2cd Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 19 Jun 2016 20:24:13 +0200 Subject: [PATCH] Remove custom fake player in favor of vanilla one, stopped using fake player for worldgen. --- .../mod/ActuallyAdditions.java | 2 - .../mod/event/WorldLoadingEvents.java | 2 - .../mod/gen/WorldGenLushCaves.java | 5 +- .../mod/util/FakePlayerUtil.java | 46 ------------------- .../actuallyadditions/mod/util/WorldUtil.java | 11 +++-- 5 files changed, 10 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/util/FakePlayerUtil.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index 044c33ecb..aa8ad0a38 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -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 diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java index eb4e353db..0e87db050 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/WorldLoadingEvents.java @@ -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 diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/WorldGenLushCaves.java b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/WorldGenLushCaves.java index a92fed062..4b1dba16c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/WorldGenLushCaves.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/WorldGenLushCaves.java @@ -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)); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/FakePlayerUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/FakePlayerUtil.java deleted file mode 100644 index 22d61c54f..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/FakePlayerUtil.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index 809170d5e..50f1494df 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -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);