mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
Fixed Tesla crash, added chunk loading system to allow for ease of future additions
This commit is contained in:
1 parent
d629fc03b7
commit
4958c40380
6 files changed
+221
-44
No files matched your search
@@ -23,7 +23,8 @@ public class ChunkManager implements LoadingCallback
|
||||
|
||||
if(tileEntity instanceof IChunkLoader)
|
||||
{
|
||||
((IChunkLoader)tileEntity).forceChunks(ticket);
|
||||
((IChunkLoader)tileEntity).getChunkLoader().refreshChunkSet();
|
||||
((IChunkLoader)tileEntity).getChunkLoader().forceChunks(ticket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
package mekanism.common.chunkloading;
|
||||
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.common.tile.component.TileComponentChunkLoader;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
|
||||
public interface IChunkLoader
|
||||
{
|
||||
public void forceChunks(Ticket ticket);
|
||||
public TileComponentChunkLoader getChunkLoader();
|
||||
|
||||
public Set<ChunkPos> getChunkSet();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public final class MekanismHooks
|
||||
if(Loader.isModLoaded("ThermalExpansion")) TELoaded = true;
|
||||
if(Loader.isModLoaded("ComputerCraft")) CCLoaded = true;
|
||||
if(Loader.isModLoaded("appliedenergistics2")) AE2Loaded = true;
|
||||
if(Loader.isModLoaded("Tesla")) TeslaLoaded = true;
|
||||
if(Loader.isModLoaded("tesla")) TeslaLoaded = true;
|
||||
|
||||
if(Loader.isModLoaded("Metallurgy3Core"))
|
||||
{
|
||||
|
||||
@@ -344,7 +344,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyAcceptorWrapper, E
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(modid = "Tesla")
|
||||
@Method(modid = "tesla")
|
||||
public long givePower(long power, boolean simulated)
|
||||
{
|
||||
return power - (long)Math.round(takeEnergy(power*general.FROM_TESLA, !simulated)*general.TO_TESLA);
|
||||
|
||||
@@ -28,6 +28,7 @@ import mekanism.common.network.PacketEntityMove.EntityMoveMessage;
|
||||
import mekanism.common.network.PacketPortalFX.PortalFXMessage;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
import mekanism.common.security.ISecurityTile;
|
||||
import mekanism.common.tile.component.TileComponentChunkLoader;
|
||||
import mekanism.common.tile.component.TileComponentSecurity;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
@@ -46,11 +47,9 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -73,8 +72,6 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
|
||||
|
||||
public List<Frequency> publicCache = new ArrayList<Frequency>();
|
||||
public List<Frequency> privateCache = new ArrayList<Frequency>();
|
||||
|
||||
public Ticket chunkTicket;
|
||||
|
||||
/** This teleporter's current status. */
|
||||
public byte status = 0;
|
||||
@@ -82,6 +79,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
|
||||
public RedstoneControl controlType = RedstoneControl.DISABLED;
|
||||
|
||||
public TileComponentSecurity securityComponent;
|
||||
public TileComponentChunkLoader chunkLoaderComponent;
|
||||
|
||||
public TileEntityTeleporter()
|
||||
{
|
||||
@@ -89,6 +87,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
|
||||
inventory = new ItemStack[1];
|
||||
|
||||
securityComponent = new TileComponentSecurity(this);
|
||||
chunkLoaderComponent = new TileComponentChunkLoader(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,20 +102,6 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
|
||||
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
if(chunkTicket == null)
|
||||
{
|
||||
Ticket ticket = ForgeChunkManager.requestTicket(Mekanism.instance, worldObj, Type.NORMAL);
|
||||
|
||||
if(ticket != null)
|
||||
{
|
||||
ticket.getModData().setInteger("xCoord", getPos().getX());
|
||||
ticket.getModData().setInteger("yCoord", getPos().getY());
|
||||
ticket.getModData().setInteger("zCoord", getPos().getZ());
|
||||
|
||||
forceChunks(ticket);
|
||||
}
|
||||
}
|
||||
|
||||
FrequencyManager manager = getManager(frequency);
|
||||
|
||||
if(manager != null)
|
||||
@@ -263,8 +248,6 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
|
||||
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
releaseChunks();
|
||||
|
||||
if(frequency != null)
|
||||
{
|
||||
FrequencyManager manager = getManager(frequency);
|
||||
@@ -760,24 +743,6 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceChunks(Ticket ticket)
|
||||
{
|
||||
releaseChunks();
|
||||
chunkTicket = ticket;
|
||||
|
||||
ForgeChunkManager.forceChunk(chunkTicket, new Chunk3D(Coord4D.get(this)).getPos());
|
||||
}
|
||||
|
||||
public void releaseChunks()
|
||||
{
|
||||
if(chunkTicket != null)
|
||||
{
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
chunkTicket = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneControl getControlType()
|
||||
{
|
||||
@@ -801,4 +766,20 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo
|
||||
{
|
||||
return securityComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileComponentChunkLoader getChunkLoader()
|
||||
{
|
||||
return chunkLoaderComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ChunkPos> getChunkSet()
|
||||
{
|
||||
Set<ChunkPos> ret = new HashSet<ChunkPos>();
|
||||
|
||||
ret.add(new Chunk3D(Coord4D.get(this)).getPos());
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package mekanism.common.tile.component;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.base.ITileComponent;
|
||||
import mekanism.common.chunkloading.IChunkLoader;
|
||||
import mekanism.common.tile.TileEntityContainerBlock;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Type;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
|
||||
public class TileComponentChunkLoader implements ITileComponent
|
||||
{
|
||||
/** TileEntity implementing this component. */
|
||||
public TileEntityContainerBlock tileEntity;
|
||||
|
||||
public Ticket chunkTicket;
|
||||
|
||||
public Set<ChunkPos> chunkSet = new HashSet<ChunkPos>();
|
||||
|
||||
public Coord4D prevCoord;
|
||||
|
||||
public TileComponentChunkLoader(TileEntityContainerBlock tile)
|
||||
{
|
||||
tileEntity = tile;
|
||||
|
||||
tile.components.add(this);
|
||||
}
|
||||
|
||||
public void setTicket(Ticket t)
|
||||
{
|
||||
if(chunkTicket != t && chunkTicket != null && chunkTicket.world == tileEntity.getWorld())
|
||||
{
|
||||
for(ChunkPos chunk : chunkTicket.getChunkList())
|
||||
{
|
||||
if(ForgeChunkManager.getPersistentChunksFor(tileEntity.getWorld()).keys().contains(chunk))
|
||||
{
|
||||
ForgeChunkManager.unforceChunk(chunkTicket, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
}
|
||||
|
||||
chunkTicket = t;
|
||||
}
|
||||
|
||||
public void release()
|
||||
{
|
||||
setTicket(null);
|
||||
}
|
||||
|
||||
public void sortChunks()
|
||||
{
|
||||
if(chunkTicket != null)
|
||||
{
|
||||
for(ChunkPos chunk : chunkTicket.getChunkList())
|
||||
{
|
||||
if(!chunkSet.contains(chunk))
|
||||
{
|
||||
if(ForgeChunkManager.getPersistentChunksFor(tileEntity.getWorld()).keys().contains(chunk))
|
||||
{
|
||||
ForgeChunkManager.unforceChunk(chunkTicket, chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(ChunkPos chunk : chunkSet)
|
||||
{
|
||||
if(!chunkTicket.getChunkList().contains(chunk))
|
||||
{
|
||||
ForgeChunkManager.forceChunk(chunkTicket, chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshChunkSet()
|
||||
{
|
||||
IChunkLoader loader = (IChunkLoader)tileEntity;
|
||||
|
||||
if(!chunkSet.equals(loader.getChunkSet()))
|
||||
{
|
||||
chunkSet = loader.getChunkSet();
|
||||
sortChunks();
|
||||
}
|
||||
}
|
||||
|
||||
public void forceChunks(Ticket ticket)
|
||||
{
|
||||
setTicket(ticket);
|
||||
|
||||
for(ChunkPos chunk : chunkSet)
|
||||
{
|
||||
ForgeChunkManager.forceChunk(chunkTicket, chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
if(!tileEntity.getWorld().isRemote)
|
||||
{
|
||||
if(prevCoord == null || !prevCoord.equals(Coord4D.get(tileEntity)))
|
||||
{
|
||||
release();
|
||||
prevCoord = Coord4D.get(tileEntity);
|
||||
}
|
||||
|
||||
if(chunkTicket != null && chunkTicket.world == tileEntity.getWorld())
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
refreshChunkSet();
|
||||
|
||||
if(chunkTicket == null)
|
||||
{
|
||||
Ticket ticket = ForgeChunkManager.requestTicket(Mekanism.instance, tileEntity.getWorld(), Type.NORMAL);
|
||||
|
||||
if(ticket != null)
|
||||
{
|
||||
ticket.getModData().setInteger("xCoord", tileEntity.getPos().getX());
|
||||
ticket.getModData().setInteger("yCoord", tileEntity.getPos().getY());
|
||||
ticket.getModData().setInteger("zCoord", tileEntity.getPos().getZ());
|
||||
|
||||
forceChunks(ticket);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
prevCoord = Coord4D.read(nbtTags.getCompoundTag("prevCoord"));
|
||||
|
||||
chunkSet.clear();
|
||||
NBTTagList list = nbtTags.getTagList("chunkSet", NBT.TAG_COMPOUND);
|
||||
|
||||
for(int i = 0; i < list.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound compound = list.getCompoundTagAt(i);
|
||||
chunkSet.add(new ChunkPos(compound.getInteger("chunkX"), compound.getInteger("chunkZ")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf dataStream) {}
|
||||
|
||||
@Override
|
||||
public void write(NBTTagCompound nbtTags)
|
||||
{
|
||||
nbtTags.setTag("prevCoord", prevCoord.write(new NBTTagCompound()));
|
||||
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for(ChunkPos pos : chunkSet)
|
||||
{
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("chunkX", pos.chunkXPos);
|
||||
compound.setInteger("chunkZ", pos.chunkZPos);
|
||||
list.appendTag(compound);
|
||||
}
|
||||
|
||||
nbtTags.setTag("chunkSet", list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ArrayList<Object> data) {}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
if(!tileEntity.getWorld().isRemote)
|
||||
{
|
||||
release();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user