mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-28 07:36:01 +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
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package mekanism.api;
|
||||
|
||||
public final class ObfuscatedNames
|
||||
{
|
||||
public static String[] Minecraft_timer = new String[] {"timer", "field_71428_T", "S"};
|
||||
public static String[] GuiContainer_xSize = new String[] {"xSize", "field_146999_f", "c"};
|
||||
public static String[] GuiContainer_ySize = new String[] {"ySize", "field_147000_g", "d"};
|
||||
public static String[] GuiContainer_guiLeft = new String[] {"guiLeft", "field_147003_i"};
|
||||
public static String[] GuiContainer_guiTop = new String[] {"guiTop", "field_147009_r"};
|
||||
public static String[] NetHandlerPlayServer_floatingTickCount = new String[] {"floatingTickCount", "field_147365_f"};
|
||||
public static String[] SoundHandler_sndManager = new String[] {"sndManager", "field_147694_f"};
|
||||
public static String[] SoundManager_sndSystem = new String[] {"sndSystem", "field_148620_e"};
|
||||
public static String[] SoundManager_invPlayingSounds = new String[] {"invPlayingSounds", "field_148630_i"};
|
||||
public static String[] AbstractClientPlayer_getPlayerInfo = new String[] {"getPlayerInfo", "func_110303_q"};
|
||||
public static String[] NetworkPlayerInfo_locationCape = new String[] {"locationCape", "field_178862_f"};
|
||||
public static String[] World_addedTileEntityList = new String[] {"addedTileEntityList", "field_147484_a"};
|
||||
}
|
||||
Reference in new issue
Block a user