Update to 1.14.2

This commit is contained in:
LexManos authored and cpw committed 2019-06-07 16:50:47 -04:00
1 parent d3e8804dbf
commit a7df63e1a1
1010 files changed
+15254 -19520

No files matched your search

@@ -22,11 +22,12 @@ package net.minecraftforge.common.util;
import java.lang.ref.WeakReference;
import java.util.Objects;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
@@ -48,24 +49,24 @@ public class BlockSnapshot
private final BlockPos pos;
private final int dimId;
@Nullable
private IBlockState replacedBlock;
private BlockState replacedBlock;
private int flag;
@Nullable
private final NBTTagCompound nbt;
private final CompoundNBT nbt;
@Nullable
private WeakReference<World> world;
private WeakReference<IWorld> world;
private final ResourceLocation registryName;
private final int meta = 0; // TODO BlockSnapshot needs a total refactor for the absence of metadata
public BlockSnapshot(World world, BlockPos pos, IBlockState state)
public BlockSnapshot(IWorld world, BlockPos pos, BlockState state)
{
this(world, pos, state, getTileNBT(world.getTileEntity(pos)));
}
public BlockSnapshot(World world, BlockPos pos, IBlockState state, @Nullable NBTTagCompound nbt)
public BlockSnapshot(IWorld world, BlockPos pos, BlockState state, @Nullable CompoundNBT nbt)
{
this.setWorld(world);
this.dimId = world.dimension.getType().getId();
this.dimId = world.getDimension().getType().getId();
this.pos = pos.toImmutable();
this.setReplacedBlock(state);
this.registryName = state.getBlock().getRegistryName();
@@ -77,7 +78,7 @@ public class BlockSnapshot
}
}
public BlockSnapshot(World world, BlockPos pos, IBlockState state, int flag)
public BlockSnapshot(IWorld world, BlockPos pos, BlockState state, int flag)
{
this(world, pos, state);
this.setFlag(flag);
@@ -86,7 +87,7 @@ public class BlockSnapshot
/**
* Raw constructor designed for serialization usages.
*/
public BlockSnapshot(int dimension, BlockPos pos, ResourceLocation registryName, int meta, int flag, @Nullable NBTTagCompound nbt)
public BlockSnapshot(int dimension, BlockPos pos, ResourceLocation registryName, int meta, int flag, @Nullable CompoundNBT nbt)
{
this.dimId = dimension;
this.pos = pos.toImmutable();
@@ -95,17 +96,17 @@ public class BlockSnapshot
this.nbt = nbt;
}
public static BlockSnapshot getBlockSnapshot(World world, BlockPos pos)
public static BlockSnapshot getBlockSnapshot(IWorld world, BlockPos pos)
{
return new BlockSnapshot(world, pos, world.getBlockState(pos));
}
public static BlockSnapshot getBlockSnapshot(World world, BlockPos pos, int flag)
public static BlockSnapshot getBlockSnapshot(IWorld world, BlockPos pos, int flag)
{
return new BlockSnapshot(world, pos, world.getBlockState(pos), flag);
}
public static BlockSnapshot readFromNBT(NBTTagCompound tag)
public static BlockSnapshot readFromNBT(CompoundNBT tag)
{
return new BlockSnapshot(
tag.getInt("dimension"),
@@ -117,31 +118,31 @@ public class BlockSnapshot
}
@Nullable
private static NBTTagCompound getTileNBT(@Nullable TileEntity te)
private static CompoundNBT getTileNBT(@Nullable TileEntity te)
{
if (te == null) return null;
NBTTagCompound nbt = new NBTTagCompound();
CompoundNBT nbt = new CompoundNBT();
te.write(nbt);
return nbt;
}
public IBlockState getCurrentBlock()
public BlockState getCurrentBlock()
{
return getWorld().getBlockState(getPos());
}
public World getWorld()
public IWorld getWorld()
{
World world = this.world != null ? this.world.get() : null;
IWorld world = this.world != null ? this.world.get() : null;
if (world == null)
{
world = ServerLifecycleHooks.getCurrentServer().getWorld(DimensionType.getById(getDimId()));
this.world = new WeakReference<World>(world);
this.world = new WeakReference<IWorld>(world);
}
return world;
}
public IBlockState getReplacedBlock()
public BlockState getReplacedBlock()
{
if (this.replacedBlock == null)
{
@@ -171,10 +172,10 @@ public class BlockSnapshot
return restoreToLocation(getWorld(), getPos(), force, notifyNeighbors);
}
public boolean restoreToLocation(World world, BlockPos pos, boolean force, boolean notifyNeighbors)
public boolean restoreToLocation(IWorld world, BlockPos pos, boolean force, boolean notifyNeighbors)
{
IBlockState current = getCurrentBlock();
IBlockState replaced = getReplacedBlock();
BlockState current = getCurrentBlock();
BlockState replaced = getReplacedBlock();
int flags = notifyNeighbors ? Constants.BlockFlags.DEFAULT : Constants.BlockFlags.NOTIFY_LISTENERS;
@@ -191,7 +192,8 @@ public class BlockSnapshot
}
world.setBlockState(pos, replaced, flags);
world.notifyBlockUpdate(pos, current, replaced, flags);
if (world instanceof World)
((World)world).notifyBlockUpdate(pos, current, replaced, flags);
TileEntity te = null;
if (getNbt() != null)
@@ -211,22 +213,22 @@ public class BlockSnapshot
return true;
}
public void writeToNBT(NBTTagCompound compound)
public void writeToNBT(CompoundNBT compound)
{
compound.setString("blockMod", getRegistryName().getNamespace());
compound.setString("blockName", getRegistryName().getPath());
compound.setInt("posX", getPos().getX());
compound.setInt("posY", getPos().getY());
compound.setInt("posZ", getPos().getZ());
compound.setInt("flag", getFlag());
compound.setInt("dimension", getDimId());
compound.setInt("metadata", getMeta());
compound.putString("blockMod", getRegistryName().getNamespace());
compound.putString("blockName", getRegistryName().getPath());
compound.putInt("posX", getPos().getX());
compound.putInt("posY", getPos().getY());
compound.putInt("posZ", getPos().getZ());
compound.putInt("flag", getFlag());
compound.putInt("dimension", getDimId());
compound.putInt("metadata", getMeta());
compound.setBoolean("hasTE", getNbt() != null);
compound.putBoolean("hasTE", getNbt() != null);
if (getNbt() != null)
{
compound.setTag("tileEntity", getNbt());
compound.func_218657_a("tileEntity", getNbt());
}
}
@@ -234,38 +236,17 @@ public class BlockSnapshot
public boolean equals(Object obj)
{
if (obj == this)
{
return true;
}
if (obj == null)
{
if (obj == null || getClass() != obj.getClass())
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
final BlockSnapshot other = (BlockSnapshot) obj;
if (this.getMeta() != other.getMeta())
{
if (this.getMeta() != other.getMeta() ||
this.getDimId() != other.getDimId() ||
!this.getPos().equals(other.getPos()) ||
!this.getRegistryName().equals(other.getRegistryName()) ||
!Objects.equals(this.getNbt(), other.getNbt()))
return false;
}
if (this.getDimId() != other.getDimId())
{
return false;
}
if (!this.getPos().equals(other.getPos()))
{
return false;
}
if (!this.getRegistryName().equals(other.getRegistryName()))
{
return false;
}
if (!Objects.equals(this.getNbt(), other.getNbt()))
{
return false;
}
return true;
}
@@ -285,16 +266,16 @@ public class BlockSnapshot
public int getDimId() { return dimId; }
public void setReplacedBlock(IBlockState replacedBlock) { this.replacedBlock = replacedBlock; }
public void setReplacedBlock(BlockState replacedBlock) { this.replacedBlock = replacedBlock; }
public int getFlag() { return flag; }
public void setFlag(int flag) { this.flag = flag; }
@Nullable
public NBTTagCompound getNbt() { return nbt; }
public CompoundNBT getNbt() { return nbt; }
public void setWorld(World world) { this.world = new WeakReference<World>(world); }
public void setWorld(IWorld world) { this.world = new WeakReference<>(world); }
public ResourceLocation getRegistryName() { return registryName; }
@@ -19,7 +19,7 @@
package net.minecraftforge.common.util;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.math.ChunkPos;
// Sorter to load nearby chunks first
@@ -28,7 +28,7 @@ public class ChunkCoordComparator implements java.util.Comparator<ChunkPos>
private int x;
private int z;
public ChunkCoordComparator(EntityPlayerMP entityplayer)
public ChunkCoordComparator(ServerPlayerEntity entityplayer)
{
x = (int) entityplayer.posX >> 4;
z = (int) entityplayer.posZ >> 4;
@@ -20,13 +20,11 @@
package net.minecraftforge.common.util;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldEventListener;
import net.minecraft.world.World;
/**
@@ -19,7 +19,7 @@
package net.minecraftforge.common.util;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.storage.WorldSavedData;
public class DummyWorldSaveData extends WorldSavedData {
@@ -29,12 +29,12 @@ public class DummyWorldSaveData extends WorldSavedData {
}
@Override
public void read(final NBTTagCompound nbt) {
public void read(final CompoundNBT nbt) {
// NOOP
}
@Override
public NBTTagCompound write(final NBTTagCompound compound) {
public CompoundNBT write(final CompoundNBT compound) {
// NOOP
return null;
}
@@ -24,23 +24,23 @@ import javax.annotation.Nullable;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.client.CPacketClientSettings;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.play.client.CClientSettingsPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerInteractionManager;
import net.minecraft.stats.Stat;
import net.minecraft.util.DamageSource;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.WorldServer;
import net.minecraft.world.ServerWorld;
import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
//Preliminary, simple Fake Player class
public class FakePlayer extends EntityPlayerMP
public class FakePlayer extends ServerPlayerEntity
{
public FakePlayer(WorldServer world, GameProfile name)
public FakePlayer(ServerWorld world, GameProfile name)
{
super(world.getServer(), world, name, new PlayerInteractionManager(world));
}
@@ -51,10 +51,9 @@ public class FakePlayer extends EntityPlayerMP
@Override public void addStat(Stat par1StatBase, int par2){}
//@Override public void openGui(Object mod, int modGuiId, World world, int x, int y, int z){}
@Override public boolean isInvulnerableTo(DamageSource source){ return true; }
@Override public boolean canAttackPlayer(EntityPlayer player){ return false; }
@Override public boolean canAttackPlayer(PlayerEntity player){ return false; }
@Override public void onDeath(DamageSource source){ return; }
@Override public void tick(){ return; }
@Override public Entity changeDimension(DimensionType dim, ITeleporter teleporter){ return this; }
@Override public void handleClientSettings(CPacketClientSettings pkt){ return; }
@Override public void handleClientSettings(CClientSettingsPacket pkt){ return; }
@Override @Nullable public MinecraftServer getServer() { return ServerLifecycleHooks.getCurrentServer(); }
}
@@ -28,7 +28,7 @@ import java.util.UUID;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile;
import net.minecraft.world.WorldServer;
import net.minecraft.world.ServerWorld;
//To be expanded for generic Mod fake players?
public class FakePlayerFactory
@@ -38,7 +38,7 @@ public class FakePlayerFactory
private static Map<GameProfile, FakePlayer> fakePlayers = Maps.newHashMap();
private static WeakReference<FakePlayer> MINECRAFT_PLAYER = null;
public static FakePlayer getMinecraft(WorldServer world)
public static FakePlayer getMinecraft(ServerWorld world)
{
FakePlayer ret = MINECRAFT_PLAYER != null ? MINECRAFT_PLAYER.get() : null;
if (ret == null)
@@ -54,7 +54,7 @@ public class FakePlayerFactory
* Mods should either hold weak references to the return value, or listen for a
* WorldEvent.Unload and kill all references to prevent worlds staying in memory.
*/
public static FakePlayer get(WorldServer world, GameProfile username)
public static FakePlayer get(ServerWorld world, GameProfile username)
{
if (!fakePlayers.containsKey(username))
{
@@ -65,7 +65,7 @@ public class FakePlayerFactory
return fakePlayers.get(username);
}
public static void unloadWorld(WorldServer world)
public static void unloadWorld(ServerWorld world)
{
fakePlayers.entrySet().removeIf(entry -> entry.getValue().world == world);
if (MINECRAFT_PLAYER != null && MINECRAFT_PLAYER.get() != null && MINECRAFT_PLAYER.get().world == world) // This shouldn't be strictly necessary, but lets be aggressive.
@@ -19,13 +19,13 @@
package net.minecraftforge.common.util;
import net.minecraft.nbt.INBTBase;
import net.minecraft.nbt.INBT;
/**
* An interface designed to unify various things in the Minecraft
* code base that can be serialized to and from a NBT tag.
*/
public interface INBTSerializable<T extends INBTBase>
public interface INBTSerializable<T extends INBT>
{
T serializeNBT();
void deserializeNBT(T nbt);
@@ -1,59 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* 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.util;
import net.minecraft.entity.Entity;
import net.minecraft.world.Teleporter;
import net.minecraft.world.World;
/**
* Interface for handling the placement of entities during dimension change.
*
* An implementation of this interface can be used to place the entity
* in a safe location, or generate a return portal, for instance.
*
* See the {@link net.minecraft.world.Teleporter} class, which has
* been patched to implement this interface, for a vanilla example.
*/
public interface ITeleporter
{
/**
* Called to handle placing the entity in the new world.
*
* The initial position of the entity will be its
* position in the origin world, multiplied horizontally
* by the computed cross-dimensional movement factor
* (see {@link WorldProvider#getMovementFactor()}).
*
* Note that the supplied entity has not yet been spawned
* in the destination world at the time.
*
* @param world the entity's destination
* @param entity the entity to be placed
* @param yaw the suggested yaw value to apply
*/
void placeEntity(World world, Entity entity, float yaw);
// used internally to handle vanilla hardcoding
default boolean isVanilla()
{
return getClass() == Teleporter.class;
}
}
@@ -39,7 +39,7 @@ import com.google.gson.JsonSyntaxException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import javax.annotation.Nullable;
@@ -97,13 +97,13 @@ public class JsonUtils
}
@Nullable
public static NBTTagCompound readNBT(JsonObject json, String key)
public static CompoundNBT readNBT(JsonObject json, String key)
{
if (net.minecraft.util.JsonUtils.hasField(json, key))
if (net.minecraft.util.JSONUtils.hasField(json, key))
{
try
{
return JsonToNBT.getTagFromJson(net.minecraft.util.JsonUtils.getString(json, key));
return JsonToNBT.getTagFromJson(net.minecraft.util.JSONUtils.getString(json, key));
} catch (CommandSyntaxException e)
{
throw new JsonSyntaxException("Malformed NBT tag", e);
@@ -21,7 +21,7 @@ package net.minecraftforge.common.util;
import javax.annotation.Nullable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.dimension.Dimension;
import net.minecraft.world.storage.WorldSavedData;
@@ -29,22 +29,22 @@ public class WorldCapabilityData extends WorldSavedData
{
public static final String ID = "capabilities";
private INBTSerializable<NBTTagCompound> serializable;
private NBTTagCompound capNBT = null;
private INBTSerializable<CompoundNBT> serializable;
private CompoundNBT capNBT = null;
public WorldCapabilityData(String name)
{
super(name);
}
public WorldCapabilityData(@Nullable INBTSerializable<NBTTagCompound> serializable)
public WorldCapabilityData(@Nullable INBTSerializable<CompoundNBT> serializable)
{
super(ID);
this.serializable = serializable;
}
@Override
public void read(NBTTagCompound nbt)
public void read(CompoundNBT nbt)
{
this.capNBT = nbt;
if (serializable != null)
@@ -55,7 +55,7 @@ public class WorldCapabilityData extends WorldSavedData
}
@Override
public NBTTagCompound write(NBTTagCompound nbt)
public CompoundNBT write(CompoundNBT nbt)
{
if (serializable != null)
nbt = serializable.serializeNBT();
@@ -68,7 +68,7 @@ public class WorldCapabilityData extends WorldSavedData
return true;
}
public void setCapabilities(Dimension provider, INBTSerializable<NBTTagCompound> capabilities)
public void setCapabilities(Dimension provider, INBTSerializable<CompoundNBT> capabilities)
{
this.serializable = capabilities;
if (this.capNBT != null && serializable != null)