mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Update adapters.
Don't update unchanged blocks, do change NBT, no need to light. Also clean up the forge side a bit.
This commit is contained in:
parent
c885f70c7b
commit
678a78a982
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -166,21 +166,19 @@ public class ForgeWorld extends AbstractWorld {
|
|||||||
boolean successful = successState != null;
|
boolean successful = successState != null;
|
||||||
|
|
||||||
// Create the TileEntity
|
// Create the TileEntity
|
||||||
if (successful) {
|
if (successful || old == newState) {
|
||||||
if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
|
if (block instanceof BaseBlock) {
|
||||||
// Kill the old TileEntity
|
CompoundTag tag = ((BaseBlock) block).getNbtData();
|
||||||
world.removeTileEntity(pos);
|
if (tag != null) {
|
||||||
NBTTagCompound nativeTag = NBTConverter.toNative(((BaseBlock) block).getNbtData());
|
NBTTagCompound nativeTag = NBTConverter.toNative(tag);
|
||||||
nativeTag.putString("id", ((BaseBlock) block).getNbtId());
|
nativeTag.putString("id", ((BaseBlock) block).getNbtId());
|
||||||
TileEntityUtils.setTileEntity(world, position, nativeTag);
|
TileEntityUtils.setTileEntity(world, position, nativeTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notifyAndLight) {
|
|
||||||
if (!successful) {
|
|
||||||
newState = old;
|
|
||||||
}
|
}
|
||||||
world.checkLight(pos);
|
|
||||||
|
if (successful && notifyAndLight) {
|
||||||
|
//world.checkLight(pos);
|
||||||
world.markAndNotifyBlock(pos, chunk, old, newState, UPDATE | NOTIFY);
|
world.markAndNotifyBlock(pos, chunk, old, newState, UPDATE | NOTIFY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,6 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,45 +44,14 @@ final class TileEntityUtils {
|
|||||||
*
|
*
|
||||||
* @param tag the tag
|
* @param tag the tag
|
||||||
* @param position the position
|
* @param position the position
|
||||||
* @return a tag compound
|
|
||||||
*/
|
*/
|
||||||
private static NBTTagCompound updateForSet(NBTTagCompound tag, BlockVector3 position) {
|
private static void updateForSet(NBTTagCompound tag, BlockVector3 position) {
|
||||||
checkNotNull(tag);
|
checkNotNull(tag);
|
||||||
checkNotNull(position);
|
checkNotNull(position);
|
||||||
|
|
||||||
tag.put("x", new NBTTagInt(position.getBlockX()));
|
tag.put("x", new NBTTagInt(position.getBlockX()));
|
||||||
tag.put("y", new NBTTagInt(position.getBlockY()));
|
tag.put("y", new NBTTagInt(position.getBlockY()));
|
||||||
tag.put("z", new NBTTagInt(position.getBlockZ()));
|
tag.put("z", new NBTTagInt(position.getBlockZ()));
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a tile entity at the given location.
|
|
||||||
*
|
|
||||||
* @param world the world
|
|
||||||
* @param position the position
|
|
||||||
* @param clazz the tile entity class
|
|
||||||
* @param tag the tag for the tile entity (may be null to not set NBT data)
|
|
||||||
*/
|
|
||||||
static void setTileEntity(World world, BlockVector3 position, Class<? extends TileEntity> clazz, @Nullable NBTTagCompound tag) {
|
|
||||||
checkNotNull(world);
|
|
||||||
checkNotNull(position);
|
|
||||||
checkNotNull(clazz);
|
|
||||||
|
|
||||||
TileEntity tileEntity = constructTileEntity(world, position, clazz);
|
|
||||||
|
|
||||||
if (tileEntity == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag != null) {
|
|
||||||
// Set X, Y, Z
|
|
||||||
updateForSet(tag, position);
|
|
||||||
tileEntity.read(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
world.setTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()), tileEntity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,42 +72,6 @@ final class TileEntityUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a tile entity from the given class.
|
|
||||||
*
|
|
||||||
* @param world the world
|
|
||||||
* @param position the position
|
|
||||||
* @param clazz the class
|
|
||||||
* @return a tile entity (may be null if it failed)
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
static TileEntity constructTileEntity(World world, BlockVector3 position, Class<? extends TileEntity> clazz) {
|
|
||||||
Constructor<? extends TileEntity> baseConstructor;
|
|
||||||
try {
|
|
||||||
baseConstructor = clazz.getConstructor(); // creates "blank" TE
|
|
||||||
} catch (Throwable e) {
|
|
||||||
return null; // every TE *should* have this constructor, so this isn't necessary
|
|
||||||
}
|
|
||||||
|
|
||||||
TileEntity genericTE;
|
|
||||||
try {
|
|
||||||
genericTE = baseConstructor.newInstance();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
genericTE.blockType = Block.blocksList[block.getId()];
|
|
||||||
genericTE.blockMetadata = block.getData();
|
|
||||||
genericTE.xCoord = pt.getBlockX();
|
|
||||||
genericTE.yCoord = pt.getBlockY();
|
|
||||||
genericTE.zCoord = pt.getBlockZ();
|
|
||||||
genericTE.worldObj = world;
|
|
||||||
*/ // handled by internal code
|
|
||||||
|
|
||||||
return genericTE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static NBTTagCompound copyNbtData(TileEntity tile) {
|
public static NBTTagCompound copyNbtData(TileEntity tile) {
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
tile.write(tag);
|
tile.write(tag);
|
||||||
|
Loading…
Reference in New Issue
Block a user