More patchwork.

This commit is contained in:
LexManos committed 2018-11-19 19:55:46 -08:00
1 parent acb7acd661
commit b6ddb0a7cf
52 files changed
+1614 -83

No files matched your search

@@ -46,6 +46,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ClassInheritanceMultiMap;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
@@ -466,8 +467,11 @@ public class ForgeChunkManager
return false;
}
static void loadWorld(World world)
static void loadWorld(IWorld iworld)
{
if (!(iworld instanceof World)) return;
World world = (World)iworld;
ArrayListMultimap<String, Ticket> newTickets = ArrayListMultimap.create();
tickets.put(world, newTickets);
@@ -617,8 +621,10 @@ public class ForgeChunkManager
}
}
static void unloadWorld(World world)
static void unloadWorld(IWorld iworld)
{
if (!(iworld instanceof World)) return;
World world = (World)iworld;
// World save fires before this event so the chunk loading info will be done
if (!(world instanceof WorldServer))
{
@@ -897,8 +903,10 @@ public class ForgeChunkManager
return forcedChunks.containsKey(world) ? forcedChunks.get(world) : ImmutableSetMultimap.of();
}
static void saveWorld(World world)
static void saveWorld(IWorld iworld)
{
if (!(iworld instanceof World)) return;
World world = (World)iworld;
// only persist persistent worlds
if (!(world instanceof WorldServer))
{
@@ -46,6 +46,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.pathfinding.PathNodeType;
import net.minecraft.state.IProperty;
import net.minecraft.state.properties.BedPart;
import net.minecraft.tags.BlockTags;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.AxisAlignedBB;
@@ -346,19 +347,6 @@ public interface IForgeBlock
*/
default void beginLeaveDecay(IBlockState state, IWorldReader world, BlockPos pos) {}
/**
* Determines if this block is considered a leaf block, used to apply the leaf decay and generation system.
*
* @param state The current state
* @param world The current world
* @param pos Block position in world
* @return true if this block is considered leaves.
*/
default boolean isLeaves(IBlockState state, IWorldReader world, BlockPos pos)
{
return state.getMaterial() == Material.LEAVES;
}
/**
* Determines this block should be treated as an air block
* by the rest of the code. This method is primarily
@@ -385,7 +373,7 @@ public interface IForgeBlock
*/
default boolean canBeReplacedByLeaves(IBlockState state, IWorldReader world, BlockPos pos)
{
return isAir(state, world, pos) || isLeaves(state, world, pos);
return isAir(state, world, pos) || state.isIn(BlockTags.LEAVES);
}
/**
@@ -441,7 +429,7 @@ public interface IForgeBlock
* @param side The side that is trying to make the connection, CAN BE NULL
* @return True to make the connection
*/
default boolean canConnectRedstone(IBlockState state, IWorldReader world, BlockPos pos, @Nullable EnumFacing side)
default boolean canConnectRedstone(IBlockState state, IBlockReader world, BlockPos pos, @Nullable EnumFacing side)
{
return state.canProvidePower() && side != null;
}
@@ -455,12 +443,12 @@ public interface IForgeBlock
* @param pos Block position in world
* @return True to allow the torch to be placed
*/
default boolean canPlaceTorchOnTop(IBlockState state, IWorldReader world, BlockPos pos)
default boolean canPlaceTorchOnTop(IBlockState state, IWorldReaderBase world, BlockPos pos)
{
if (state.isTopSolid() || state.getBlockFaceShape(world, pos, EnumFacing.UP) == BlockFaceShape.SOLID)
return this.getBlock() != Blocks.END_GATEWAY && this.getBlock() != Blocks.JACK_O_LANTERN;
return this.getBlock() != Blocks.END_GATEWAY;
else
return this.getBlock() instanceof BlockFence || this.getBlock() == Blocks.COBBLESTONE_WALL || this.getBlock() instanceof BlockGlass;
return this.getBlock() instanceof BlockFence || this.getBlock() instanceof BlockStainedGlass || this.getBlock() == Blocks.GLASS || this.getBlock() == Blocks.COBBLESTONE_WALL || this.getBlock() == Blocks.MOSSY_COBBLESTONE_WALL;
}
/**
@@ -43,6 +43,7 @@ import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.IWorldReaderBase;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.api.distmarker.Dist;
@@ -297,18 +298,6 @@ public interface IForgeBlockState
getBlockState().getBlock().beginLeaveDecay(getBlockState(), world, pos);
}
/**
* Determines if this block is considered a leaf block, used to apply the leaf decay and generation system.
*
* @param world The current world
* @param pos Block position in world
* @return true if this block is considered leaves.
*/
default boolean isLeaves(IWorldReader world, BlockPos pos)
{
return getBlockState().getBlock().isLeaves(getBlockState(), world, pos);
}
/**
* Determines this block should be treated as an air block
* by the rest of the code. This method is primarily
@@ -387,7 +376,7 @@ public interface IForgeBlockState
* @param side The side that is trying to make the connection, CAN BE NULL
* @return True to make the connection
*/
default boolean canConnectRedstone(IWorldReader world, BlockPos pos, @Nullable EnumFacing side)
default boolean canConnectRedstone(IBlockReader world, BlockPos pos, @Nullable EnumFacing side)
{
return getBlockState().getBlock().canConnectRedstone(getBlockState(), world, pos, side);
}
@@ -400,7 +389,7 @@ public interface IForgeBlockState
* @param pos Block position in world
* @return True to allow the torch to be placed
*/
default boolean canPlaceTorchOnTop(IWorldReader world, BlockPos pos)
default boolean canPlaceTorchOnTop(IWorldReaderBase world, BlockPos pos)
{
return getBlockState().getBlock().canPlaceTorchOnTop(getBlockState(), world, pos);
}
@@ -0,0 +1,191 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2018.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common.extensions;
import net.minecraft.block.BlockRailBase;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.MoverType;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.item.EntityMinecartChest;
import net.minecraft.entity.item.EntityMinecartCommandBlock;
import net.minecraft.entity.item.EntityMinecartFurnace;
import net.minecraft.entity.item.EntityMinecartHopper;
import net.minecraft.entity.item.EntityMinecartTNT;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.IMinecartCollisionHandler;
public interface IForgeEntityMinecart
{
public static float DEFAULT_MAX_SPEED_AIR_LATERAL = 0.4f;
public static float DEFAULT_MAX_SPEED_AIR_VERTICAL = -1.0f;
public static double DEFAULT_AIR_DRAG = 0.95f;
public static IMinecartCollisionHandler COLLISIONS = null;
default EntityMinecart getMinecart() {
return (EntityMinecart)this;
}
/**
* Gets the current global Minecart Collision handler if none
* is registered, returns null
* @return The collision handler or null
*/
default IMinecartCollisionHandler getCollisionHandler() {
return COLLISIONS;
}
/**
* Internal, returns the current spot to look for the attached rail.
*/
default BlockPos getCurrentRailPosition()
{
int x = MathHelper.floor(getMinecart().posX);
int y = MathHelper.floor(getMinecart().posY);
int z = MathHelper.floor(getMinecart().posZ);
BlockPos pos = new BlockPos(x, y - 1, z);
if (getMinecart().world.getBlockState(pos).isIn(BlockTags.RAILS)) pos = pos.down();
return pos;
}
double getMaxSpeed();
/**
* Moved to allow overrides.
* This code handles minecart movement and speed capping when on a rail.
*/
default void moveMinecartOnRail(BlockPos pos)
{
EntityMinecart mc = getMinecart();
double mX = mc.motionX;
double mZ = mc.motionZ;
if (mc.isBeingRidden())
{
mX *= 0.75D;
mZ *= 0.75D;
}
double max = getMaxSpeed();
mX = MathHelper.clamp(mX, -max, max);
mZ = MathHelper.clamp(mZ, -max, max);
mc.move(MoverType.SELF, mX, 0.0D, mZ);
}
/**
* This function returns an ItemStack that represents this cart.
* This should be an ItemStack that can be used by the player to place the cart,
* but is not necessary the item the cart drops when destroyed.
* @return An ItemStack that can be used to place the cart.
*/
default ItemStack getCartItem()
{
switch (getMinecart().getMinecartType())
{
case FURNACE: return new ItemStack(Items.FURNACE_MINECART);
case CHEST: return new ItemStack(Items.CHEST_MINECART);
case TNT: return new ItemStack(Items.TNT_MINECART);
case HOPPER: return new ItemStack(Items.HOPPER_MINECART);
case COMMAND_BLOCK: return new ItemStack(Items.COMMAND_BLOCK_MINECART);
default: return new ItemStack(Items.MINECART);
}
}
/**
* Returns true if this cart can currently use rails.
* This function is mainly used to gracefully detach a minecart from a rail.
* @return True if the minecart can use rails.
*/
boolean canUseRail();
/**
* Set whether the minecart can use rails.
* This function is mainly used to gracefully detach a minecart from a rail.
* @param use Whether the minecart can currently use rails.
*/
void setCanUseRail(boolean use);
/**
* Return false if this cart should not call onMinecartPass() and should ignore Powered Rails.
* @return True if this cart should call onMinecartPass().
*/
default boolean shouldDoRailFunctions() {
return true;
}
/**
* Returns true if this cart is self propelled.
* @return True if powered.
*/
default boolean isPoweredCart() {
return getMinecart().getMinecartType() == EntityMinecart.Type.FURNACE;
}
/**
* Returns true if this cart can be ridden by an Entity.
* @return True if this cart can be ridden.
*/
default boolean canBeRidden() {
return getMinecart().getMinecartType() == EntityMinecart.Type.RIDEABLE;
}
/**
* Returns the carts max speed when traveling on rails. Carts going faster
* than 1.1 cause issues with chunk loading. Carts cant traverse slopes or
* corners at greater than 0.5 - 0.6. This value is compared with the rails
* max speed and the carts current speed cap to determine the carts current
* max speed. A normal rail's max speed is 0.4.
*
* @return Carts max speed.
*/
default float getMaxCartSpeedOnRail() {
return 1.2f;
}
/**
* Returns the current speed cap for the cart when traveling on rails. This
* functions differs from getMaxCartSpeedOnRail() in that it controls
* current movement and cannot be overridden. The value however can never be
* higher than getMaxCartSpeedOnRail().
*
* @return
*/
float getCurrentCartSpeedCapOnRail();
void setCurrentCartSpeedCapOnRail(float value);
float getMaxSpeedAirLateral();
void setMaxSpeedAirLateral(float value);
float getMaxSpeedAirVertical();
void setMaxSpeedAirVertical(float value);
double getDragAir();
void setDragAir(double value);
default double getSlopeAdjustment() {
return 0.0078125D;
}
/**
* Called from Detector Rails to retrieve a redstone power level for comparators.
*/
default int getComparatorLevel() {
return -1;
}
}
@@ -62,6 +62,7 @@ import net.minecraft.util.text.ChatType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.village.Village;
import net.minecraft.world.Explosion;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
@@ -191,13 +192,9 @@ public class ForgeEventFactory
{
Result result = canEntitySpawn(entity, world, x, y, z, spawner);
if (result == Result.DEFAULT)
{
return entity.getCanSpawnHere() && entity.isNotColliding(); // vanilla logic
}
else
{
return result == Result.ALLOW;
}
}
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z, MobSpawnerBaseLogic spawner)
@@ -675,7 +672,7 @@ public class ForgeEventFactory
return result == Result.DEFAULT ? def : result == Result.ALLOW;
}
public static boolean onTrySpawnPortal(World world, BlockPos pos, BlockPortal.Size size)
public static boolean onTrySpawnPortal(IWorld world, BlockPos pos, BlockPortal.Size size)
{
return MinecraftForge.EVENT_BUS.post(new BlockEvent.PortalSpawnEvent(world, pos, world.getBlockState(pos), size));
}
@@ -27,6 +27,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event.HasResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
@@ -51,7 +52,7 @@ public class SaplingGrowTreeEvent extends WorldEvent
private final BlockPos pos;
private final Random rand;
public SaplingGrowTreeEvent(World world, Random rand, BlockPos pos)
public SaplingGrowTreeEvent(IWorld world, Random rand, BlockPos pos)
{
super(world);
this.rand = rand;
@@ -23,6 +23,7 @@ import java.util.Random;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraftforge.common.MinecraftForge;
@@ -107,7 +108,7 @@ public abstract class TerrainGen
}
*/
public static boolean saplingGrowTree(World world, Random rand, BlockPos pos)
public static boolean saplingGrowTree(IWorld world, Random rand, BlockPos pos)
{
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(world, rand, pos);
MinecraftForge.TERRAIN_GEN_BUS.post(event);
@@ -33,6 +33,7 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.BlockSnapshot;
@@ -49,17 +50,17 @@ public class BlockEvent extends Event
{
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
private final World world;
private final IWorld world;
private final BlockPos pos;
private final IBlockState state;
public BlockEvent(World world, BlockPos pos, IBlockState state)
public BlockEvent(IWorld world, BlockPos pos, IBlockState state)
{
this.pos = pos;
this.world = world;
this.state = state;
}
public World getWorld()
public IWorld getWorld()
{
return world;
}
@@ -435,7 +436,7 @@ public class BlockEvent extends Event
{
private final BlockPortal.Size size;
public PortalSpawnEvent(World world, BlockPos pos, IBlockState state, BlockPortal.Size size)
public PortalSpawnEvent(IWorld world, BlockPos pos, IBlockState state, BlockPortal.Size size)
{
super(world, pos, state);
this.size = size;
@@ -33,6 +33,7 @@ import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.IProgressUpdate;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
@@ -51,14 +52,14 @@ import net.minecraftforge.eventbus.api.Event;
**/
public class WorldEvent extends Event
{
private final World world;
private final IWorld world;
public WorldEvent(World world)
public WorldEvent(IWorld world)
{
this.world = world;
}
public World getWorld()
public IWorld getWorld()
{
return world;
}
@@ -80,7 +81,7 @@ public class WorldEvent extends Event
**/
public static class Load extends WorldEvent
{
public Load(World world) { super(world); }
public Load(IWorld world) { super(world); }
}
/**
@@ -99,7 +100,7 @@ public class WorldEvent extends Event
**/
public static class Unload extends WorldEvent
{
public Unload(World world) { super(world); }
public Unload(IWorld world) { super(world); }
}
/**
@@ -116,7 +117,7 @@ public class WorldEvent extends Event
**/
public static class Save extends WorldEvent
{
public Save(World world) { super(world); }
public Save(IWorld world) { super(world); }
}
/**
@@ -134,7 +135,7 @@ public class WorldEvent extends Event
private final BlockPos pos;
private final List<SpawnListEntry> list;
public PotentialSpawns(World world, EnumCreatureType type, BlockPos pos, List<SpawnListEntry> oldList)
public PotentialSpawns(IWorld world, EnumCreatureType type, BlockPos pos, List<SpawnListEntry> oldList)
{
super(world);
this.pos = pos;
@@ -173,7 +174,7 @@ public class WorldEvent extends Event
public static class CreateSpawnPosition extends WorldEvent
{
private final WorldSettings settings;
public CreateSpawnPosition(World world, WorldSettings settings)
public CreateSpawnPosition(IWorld world, WorldSettings settings)
{
super(world);
this.settings = settings;
@@ -28,6 +28,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityDispenser;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
@@ -24,6 +24,7 @@ import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
import net.minecraft.block.Block;
import net.minecraft.block.IBucketPickupHandler;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;