mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 12:59:41 +00:00
Work on TileEntity stuff. Details below.
I've added the method "Coord4D.safeTileGet()" which is likely going to be necessary in a lot of cases where duplicate TEs could be created- for some reason World.getTileEntity() fails to return the saved TileEntity fairly often.
This commit is contained in:
1 parent
fc7b185805
commit
eba5f7e356
20 files changed
+108
-75
No files matched your search
@@ -3,7 +3,9 @@ package mekanism.api;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -20,6 +22,7 @@ import net.minecraft.util.Vec3i;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.Chunk.EnumCreateEntityType;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
|
||||
/**
|
||||
@@ -44,6 +47,11 @@ public class Coord4D extends BlockPos
|
||||
|
||||
dimensionId = 0;
|
||||
}
|
||||
|
||||
public Coord4D(int x, int y, int z, World world)
|
||||
{
|
||||
this(x, y, z, world.provider.getDimensionId());
|
||||
}
|
||||
|
||||
public Coord4D(double x, double y, double z)
|
||||
{
|
||||
@@ -130,7 +138,42 @@ public class Coord4D extends BlockPos
|
||||
|
||||
return (tile != null && tile.hasWorldObj() && !tile.isInvalid()) ? tile : null;
|
||||
}
|
||||
|
||||
|
||||
public TileEntity safeTileGet(World world)
|
||||
{
|
||||
if(!exists(world))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getChunkFromBlockCoords(this).getTileEntity(this, EnumCreateEntityType.CHECK);
|
||||
|
||||
if(tile != null)
|
||||
{
|
||||
return tile;
|
||||
}
|
||||
|
||||
for(TileEntity iter : world.loadedTileEntityList)
|
||||
{
|
||||
if(!iter.isInvalid() && iter.getPos().equals(this))
|
||||
{
|
||||
return iter;
|
||||
}
|
||||
}
|
||||
|
||||
List<TileEntity> added = (List<TileEntity>)MekanismUtils.getPrivateValue(world, World.class, ObfuscatedNames.World_addedTileEntityList);
|
||||
|
||||
for(TileEntity iter : added)
|
||||
{
|
||||
if(!iter.isInvalid() && iter.getPos().equals(this))
|
||||
{
|
||||
return iter;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Block value of the block representing this Coord4D.
|
||||
* @param world - world this Coord4D is in
|
||||
|
||||
Reference in new issue
Block a user