Fixed Network and TileEnties
This commit is contained in:
parent
bdf7532b14
commit
a1254ae8d5
21 changed files with 161 additions and 287 deletions
|
@ -4,17 +4,17 @@ import com.zixiken.dimdoors.config.DDProperties;
|
|||
import com.zixiken.dimdoors.network.packets.ClientJoinPacket;
|
||||
import com.zixiken.dimdoors.network.DimDoorsNetwork;
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import com.zixiken.dimdoors.core.NewDimData;
|
||||
import net.minecraftforge.common.network.ForgeMessage;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
import net.minecraftforge.fml.common.network.FMLEmbeddedChannel;
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
public class ConnectionHandler
|
||||
{
|
||||
|
|
|
@ -65,8 +65,7 @@ public class BlockDimWall extends Block {
|
|||
else return SUPER_EXPLOSION_RESISTANCE;
|
||||
}
|
||||
|
||||
public int getRenderType()
|
||||
{
|
||||
public int getRenderType() {
|
||||
return PrivatePocketRender.renderID;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.zixiken.dimdoors.DimDoors;
|
|||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import com.zixiken.dimdoors.world.PocketBuilder;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
|
@ -20,50 +21,40 @@ import com.zixiken.dimdoors.Point3D;
|
|||
import com.zixiken.dimdoors.core.NewDimData;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
|
||||
public class ChunkLoaderHelper implements LoadingCallback
|
||||
{
|
||||
public class ChunkLoaderHelper implements LoadingCallback {
|
||||
@Override
|
||||
public void ticketsLoaded(List<Ticket> tickets, World world)
|
||||
{
|
||||
for (Ticket ticket : tickets)
|
||||
{
|
||||
public void ticketsLoaded(List<Ticket> tickets, World world) {
|
||||
for (Ticket ticket : tickets) {
|
||||
boolean loaded = false;
|
||||
int x = ticket.getModData().getInteger("goldDimDoorX");
|
||||
int y = ticket.getModData().getInteger("goldDimDoorY");
|
||||
int z = ticket.getModData().getInteger("goldDimDoorZ");
|
||||
BlockPos pos = new BlockPos(ticket.getModData().getInteger("goldDimDoor"), ticket.getModData().getInteger("goldDimDoorY"), ticket.getModData().getInteger("goldDimDoorZ"));
|
||||
|
||||
if (world.getBlock(x, y, z) == DimDoors.goldenDimensionalDoor)
|
||||
{
|
||||
IChunkLoader loader = (IChunkLoader) world.getTileEntity(x, y, z);
|
||||
if (!loader.isInitialized())
|
||||
{
|
||||
if (world.getBlockState(pos).getBlock() == DimDoors.goldenDimensionalDoor) {
|
||||
IChunkLoader loader = (IChunkLoader) world.getTileEntity(pos);
|
||||
if (!loader.isInitialized()) {
|
||||
loader.initialize(ticket);
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
if (!loaded)
|
||||
{
|
||||
}if (!loaded) {
|
||||
ForgeChunkManager.releaseTicket(ticket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Ticket createTicket(int x, int y, int z, World world)
|
||||
public static Ticket createTicket(BlockPos pos, World world)
|
||||
{
|
||||
NBTTagCompound data;
|
||||
Ticket ticket = ForgeChunkManager.requestTicket(DimDoors.instance, world, Type.NORMAL);
|
||||
if (ticket != null)
|
||||
{
|
||||
data = ticket.getModData();
|
||||
data.setInteger("goldDimDoorX", x);
|
||||
data.setInteger("goldDimDoorY", y);
|
||||
data.setInteger("goldDimDoorZ", z);
|
||||
data.setInteger("goldDimDoorX", pos.getX());
|
||||
data.setInteger("goldDimDoorY", pos.getY());
|
||||
data.setInteger("goldDimDoorZ", pos.getZ());
|
||||
}
|
||||
return ticket;
|
||||
}
|
||||
|
||||
public static void forcePocketChunks(NewDimData pocket, Ticket ticket)
|
||||
{
|
||||
public static void forcePocketChunks(NewDimData pocket, Ticket ticket) {
|
||||
BoundingBox bounds = PocketBuilder.calculateDefaultBounds(pocket);
|
||||
BlockPos minCorner = bounds.minCorner();
|
||||
BlockPos maxCorner = bounds.maxCorner();
|
||||
|
@ -74,27 +65,21 @@ public class ChunkLoaderHelper implements LoadingCallback
|
|||
int chunkX;
|
||||
int chunkZ;
|
||||
|
||||
for (chunkX = minX; chunkX <= maxX; chunkX++)
|
||||
{
|
||||
for (chunkZ = minZ; chunkZ <= maxZ; chunkZ++)
|
||||
{
|
||||
for (chunkX = minX; chunkX <= maxX; chunkX++) {
|
||||
for (chunkZ = minZ; chunkZ <= maxZ; chunkZ++) {
|
||||
ForgeChunkManager.forceChunk(ticket, new ChunkCoordIntPair(chunkX, chunkZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadForcedChunkWorlds(FMLServerStartingEvent event)
|
||||
{
|
||||
for (NewDimData data : PocketManager.getDimensions())
|
||||
{
|
||||
if(data.isPocketDimension())
|
||||
{
|
||||
public static void loadForcedChunkWorlds(FMLServerStartingEvent event) {
|
||||
for (NewDimData data : PocketManager.getDimensions()) {
|
||||
if(data.isPocketDimension()) {
|
||||
String chunkDir = DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoors/pocketDimID" + data.id();
|
||||
|
||||
File file = new File(chunkDir);
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
if(file.exists()) {
|
||||
if(ForgeChunkManager.savedWorldHasForcedChunkTickets(file))
|
||||
{
|
||||
PocketManager.loadDimension(data.id());
|
||||
|
|
|
@ -3,23 +3,17 @@ package com.zixiken.dimdoors.network;
|
|||
import com.zixiken.dimdoors.DimDoors;
|
||||
import com.zixiken.dimdoors.network.handlers.*;
|
||||
import com.zixiken.dimdoors.network.packets.*;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class DimDoorsNetwork extends SimpleNetworkWrapper {
|
||||
|
||||
private static final DimDoorsNetwork INSTANCE = new DimDoorsNetwork(DimDoors.modid);
|
||||
private static final DimDoorsNetwork INSTANCE = new DimDoorsNetwork(DimDoors.MODID);
|
||||
|
||||
public DimDoorsNetwork(String channelName) {
|
||||
super(channelName);
|
||||
|
|
|
@ -4,10 +4,10 @@ import com.zixiken.dimdoors.DimDoors;
|
|||
import com.zixiken.dimdoors.core.NewDimData;
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import com.zixiken.dimdoors.network.packets.ClientJoinPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class ClientJoinHandler implements IMessageHandler<ClientJoinPacket, IMessage> {
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.zixiken.dimdoors.network.handlers;
|
|||
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import com.zixiken.dimdoors.network.packets.CreateDimensionPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class CreateDimensionHandler implements IMessageHandler<CreateDimensionPacket, IMessage> {
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.zixiken.dimdoors.network.handlers;
|
|||
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import com.zixiken.dimdoors.network.packets.CreateLinkPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class CreateLinkHandler implements IMessageHandler<CreateLinkPacket, IMessage> {
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.zixiken.dimdoors.network.handlers;
|
|||
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import com.zixiken.dimdoors.network.packets.DeleteDimensionPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class DeleteDimensionHandler implements IMessageHandler<DeleteDimensionPacket, IMessage> {
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.zixiken.dimdoors.network.handlers;
|
|||
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import com.zixiken.dimdoors.network.packets.DeleteLinkPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class DeleteLinkHandler implements IMessageHandler<DeleteLinkPacket, IMessage> {
|
||||
@Override
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.zixiken.dimdoors.network.handlers;
|
|||
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import com.zixiken.dimdoors.network.packets.UpdateLinkPacket;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class UpdateLinkHandler implements IMessageHandler<UpdateLinkPacket, IMessage> {
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.zixiken.dimdoors.network.packets;
|
||||
|
||||
import com.zixiken.dimdoors.core.PocketManager;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.zixiken.dimdoors.network.packets;
|
||||
|
||||
import com.zixiken.dimdoors.watcher.ClientDimData;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.zixiken.dimdoors.network.packets;
|
||||
|
||||
import com.zixiken.dimdoors.watcher.ClientLinkData;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package com.zixiken.dimdoors.network.packets;
|
||||
|
||||
import com.zixiken.dimdoors.watcher.ClientDimData;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.zixiken.dimdoors.network.packets;
|
||||
|
||||
import com.zixiken.dimdoors.watcher.ClientLinkData;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.zixiken.dimdoors.network.packets;
|
||||
|
||||
import com.zixiken.dimdoors.watcher.ClientLinkData;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -7,33 +7,26 @@ public class RiftTicket implements Comparable<RiftTicket> {
|
|||
private long timestamp;
|
||||
private Point4D location;
|
||||
|
||||
public RiftTicket(Point4D location, long timestamp)
|
||||
{
|
||||
public RiftTicket(Point4D location, long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(RiftTicket other)
|
||||
{
|
||||
if (this.timestamp < other.timestamp)
|
||||
{
|
||||
public int compareTo(RiftTicket other) {
|
||||
if (this.timestamp < other.timestamp) {
|
||||
return -1;
|
||||
}
|
||||
else if (this.timestamp > other.timestamp)
|
||||
{
|
||||
} else if (this.timestamp > other.timestamp) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long timestamp()
|
||||
{
|
||||
public long timestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public Point4D location()
|
||||
{
|
||||
public Point4D location() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,41 +10,34 @@ import com.zixiken.dimdoors.watcher.ClientLinkData;
|
|||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
|
||||
public class TileEntityDimDoor extends DDTileEntityBase
|
||||
{
|
||||
public boolean openOrClosed;
|
||||
public int orientation;
|
||||
public EnumFacing orientation;
|
||||
public boolean hasExit;
|
||||
public byte lockStatus;
|
||||
public boolean isDungeonChainLink;
|
||||
public boolean hasGennedPair=false;
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
if(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj)!=null)
|
||||
{
|
||||
ClientLinkData linkData = new ClientLinkData(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj));
|
||||
if(PocketManager.getLink(pos, worldObj)!=null) {
|
||||
ClientLinkData linkData = new ClientLinkData(PocketManager.getLink(pos, worldObj));
|
||||
NBTTagCompound link = new NBTTagCompound();
|
||||
linkData.writeToNBT(link);
|
||||
tag.setTag("Link", link);
|
||||
}
|
||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tag);
|
||||
return new S35PacketUpdateTileEntity(pos, 1, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
NBTTagCompound tag = pkt.func_148857_g();
|
||||
NBTTagCompound tag = pkt.getNbtCompound();
|
||||
readFromNBT(tag);
|
||||
|
||||
if (tag.hasKey("Link")) {
|
||||
|
@ -54,52 +47,42 @@ public class TileEntityDimDoor extends DDTileEntityBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
this.openOrClosed = nbt.getBoolean("openOrClosed");
|
||||
this.orientation = nbt.getInteger("orientation");
|
||||
this.orientation = EnumFacing.getFront(nbt.getInteger("orientation"));
|
||||
this.hasExit = nbt.getBoolean("hasExit");
|
||||
this.isDungeonChainLink = nbt.getBoolean("isDungeonChainLink");
|
||||
this.hasGennedPair = nbt.getBoolean("hasGennedPair");
|
||||
}
|
||||
catch (Exception e) // ???
|
||||
{
|
||||
|
||||
}
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setBoolean("openOrClosed", this.openOrClosed);
|
||||
nbt.setBoolean("hasExit", this.hasExit);
|
||||
nbt.setInteger("orientation", this.orientation);
|
||||
nbt.setInteger("orientation", this.orientation.getIndex());
|
||||
nbt.setBoolean("isDungeonChainLink", isDungeonChainLink);
|
||||
nbt.setBoolean("hasGennedPair", hasGennedPair);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] getRenderColor(Random rand)
|
||||
{
|
||||
public float[] getRenderColor(Random rand) {
|
||||
float[] rgbaColor = {1,1,1,1};
|
||||
if (this.worldObj.provider.dimensionId == DimDoors.NETHER_DIMENSION_ID)
|
||||
{
|
||||
if (this.worldObj.provider.getDimensionId() == DimDoors.NETHER_DIMENSION_ID) {
|
||||
rgbaColor[0] = rand.nextFloat() * 0.5F + 0.4F;
|
||||
rgbaColor[1] = rand.nextFloat() * 0.05F;
|
||||
rgbaColor[2] = rand.nextFloat() * 0.05F;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rgbaColor[0] = rand.nextFloat() * 0.5F + 0.1F;
|
||||
rgbaColor[1] = rand.nextFloat() * 0.4F + 0.4F;
|
||||
rgbaColor[2] = rand.nextFloat() * 0.6F + 0.5F;
|
||||
}
|
||||
|
||||
return rgbaColor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,35 +8,17 @@ import com.zixiken.dimdoors.world.PocketBuilder;
|
|||
import net.minecraftforge.common.ForgeChunkManager;
|
||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||
|
||||
public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLoader
|
||||
{
|
||||
public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLoader {
|
||||
private Ticket chunkTicket;
|
||||
private boolean initialized = false;
|
||||
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return !initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized()
|
||||
{
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
initialize(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Ticket ticket)
|
||||
{
|
||||
public void initialize(Ticket ticket) {
|
||||
initialized = true;
|
||||
chunkTicket = ticket;
|
||||
|
||||
|
@ -44,26 +26,20 @@ public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLo
|
|||
// NOTE: We don't have to check whether this block is the upper door
|
||||
// block or the lower one because only one of them should have a
|
||||
// link associated with it.
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (!worldObj.isRemote) {
|
||||
NewDimData dimension = PocketManager.createDimensionData(worldObj);
|
||||
|
||||
// Check whether a ticket has already been assigned to this door
|
||||
if (chunkTicket == null)
|
||||
{
|
||||
if (chunkTicket == null) {
|
||||
// No ticket yet.
|
||||
// Check if this area should be loaded and request a new ticket.
|
||||
if (isValidChunkLoaderSetup(dimension))
|
||||
{
|
||||
chunkTicket = ChunkLoaderHelper.createTicket(xCoord, yCoord, zCoord, worldObj);
|
||||
if (isValidChunkLoaderSetup(dimension)) {
|
||||
chunkTicket = ChunkLoaderHelper.createTicket(pos, worldObj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// A ticket has already been provided.
|
||||
// Check if this area should be loaded. If not, release the ticket.
|
||||
if (!isValidChunkLoaderSetup(dimension))
|
||||
{
|
||||
if (!isValidChunkLoaderSetup(dimension)) {
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
chunkTicket = null;
|
||||
}
|
||||
|
@ -71,28 +47,25 @@ public class TileEntityDimDoorGold extends TileEntityDimDoor implements IChunkLo
|
|||
|
||||
// If chunkTicket isn't null at this point, then this is a valid door setup.
|
||||
// The last step is to request force loading of the pocket's chunks.
|
||||
if (chunkTicket != null)
|
||||
{
|
||||
if (chunkTicket != null) {
|
||||
ChunkLoaderHelper.forcePocketChunks(dimension, chunkTicket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidChunkLoaderSetup(NewDimData dimension)
|
||||
{
|
||||
private boolean isValidChunkLoaderSetup(NewDimData dimension) {
|
||||
// Check the various conditions that make this a valid door setup.
|
||||
// 1. The door must be inside the pocket's XZ boundaries,
|
||||
// to prevent loading of chunks with a distant door
|
||||
// 2. The dimension must be a pocket dimension
|
||||
// 3. The door must be linked so that it's clear that it's not a normal door
|
||||
|
||||
return (dimension.isPocketDimension() && dimension.getLink(xCoord, yCoord, zCoord) != null &&
|
||||
PocketBuilder.calculateDefaultBounds(dimension).contains(xCoord, yCoord, zCoord));
|
||||
return (dimension.isPocketDimension() && dimension.getLink(pos) != null &&
|
||||
PocketBuilder.calculateDefaultBounds(dimension).contains(pos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
public void invalidate() {
|
||||
ForgeChunkManager.releaseTicket(chunkTicket);
|
||||
super.invalidate();
|
||||
}
|
||||
|
|
|
@ -18,8 +18,10 @@ import net.minecraft.util.AxisAlignedBB;
|
|||
import com.zixiken.dimdoors.core.NewDimData;
|
||||
import com.zixiken.dimdoors.util.Point4D;
|
||||
import com.zixiken.dimdoors.watcher.ClientLinkData;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.ITickable;
|
||||
|
||||
public class TileEntityRift extends DDTileEntityBase
|
||||
public class TileEntityRift extends DDTileEntityBase implements ITickable
|
||||
{
|
||||
private static final int RIFT_INTERACTION_RANGE = 5;
|
||||
private static final int MAX_ANCESTOR_LINKS = 2;
|
||||
|
@ -37,9 +39,7 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
|
||||
private int updateTimer;
|
||||
private int closeTimer = 0;
|
||||
public int xOffset = 0;
|
||||
public int yOffset = 0;
|
||||
public int zOffset = 0;
|
||||
public BlockPos offset = BlockPos.ORIGIN;
|
||||
public boolean shouldClose = false;
|
||||
public Point4D nearestRiftLocation = null;
|
||||
public int spawnedEndermenID = 0;
|
||||
|
@ -47,32 +47,24 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
public int riftRotation = random.nextInt(360);
|
||||
public float growth = 0;
|
||||
|
||||
public TileEntityRift()
|
||||
{
|
||||
public TileEntityRift() {
|
||||
// Vary the update times of rifts to prevent all the rifts in a cluster
|
||||
// from updating at the same time.
|
||||
updateTimer = random.nextInt(UPDATE_PERIOD);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if (PocketManager.getLink(xCoord, yCoord, zCoord, worldObj.provider.dimensionId) == null)
|
||||
{
|
||||
if (worldObj.getBlock(xCoord, yCoord, zCoord) == DimDoors.blockRift)
|
||||
{
|
||||
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
||||
}
|
||||
else
|
||||
{
|
||||
public void update() {
|
||||
if (PocketManager.getLink(pos, worldObj.provider.getDimensionId()) == null) {
|
||||
if (worldObj.getBlockState(pos).getBlock() == DimDoors.blockRift) {
|
||||
worldObj.setBlockToAir(pos);
|
||||
} else {
|
||||
invalidate();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldObj.getBlock(xCoord, yCoord, zCoord) != DimDoors.blockRift)
|
||||
{
|
||||
if (worldObj.getBlockState(pos).getBlock() != DimDoors.blockRift) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
|
@ -80,19 +72,16 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
|
||||
// Check if this rift should render white closing particles and
|
||||
// spread the closing effect to other rifts nearby.
|
||||
if (shouldClose)
|
||||
{
|
||||
if (shouldClose) {
|
||||
closeRift();
|
||||
return;
|
||||
}
|
||||
|
||||
if (updateTimer >= UPDATE_PERIOD)
|
||||
{
|
||||
if (updateTimer >= UPDATE_PERIOD) {
|
||||
spawnEndermen(DimDoors.properties);
|
||||
updateTimer = 0;
|
||||
}
|
||||
else if (updateTimer == UPDATE_PERIOD / 2)
|
||||
{
|
||||
else if (updateTimer == UPDATE_PERIOD / 2) {
|
||||
updateNearestRift();
|
||||
spread(DimDoors.properties);
|
||||
}
|
||||
|
@ -102,38 +91,31 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
|
||||
private void spawnEndermen(DDProperties properties)
|
||||
{
|
||||
if (worldObj.isRemote || !properties.RiftsSpawnEndermenEnabled)
|
||||
{
|
||||
if (worldObj.isRemote || !properties.RiftsSpawnEndermenEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure that this rift is only spawning one Enderman at a time, to prevent hordes of Endermen
|
||||
Entity entity = worldObj.getEntityByID(this.spawnedEndermenID);
|
||||
if (entity != null && entity instanceof EntityEnderman)
|
||||
{
|
||||
if (entity != null && entity instanceof EntityEnderman) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE)
|
||||
{
|
||||
if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE) {
|
||||
// Endermen will only spawn from groups of rifts
|
||||
if (updateNearestRift())
|
||||
{
|
||||
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityEnderman.class,
|
||||
AxisAlignedBB.getBoundingBox(xCoord - 9, yCoord - 3, zCoord - 9, xCoord + 9, yCoord + 3, zCoord + 9));
|
||||
if (updateNearestRift()) {
|
||||
List<EntityEnderman> list = worldObj.getEntitiesWithinAABB(EntityEnderman.class,
|
||||
AxisAlignedBB.fromBounds(pos.getX() - 9, pos.getY() - 3, pos.getZ() - 9, pos.getX() + 9, pos.getY() + 3, pos.getZ() + 9));
|
||||
|
||||
if (list.isEmpty())
|
||||
{
|
||||
if (list.isEmpty()) {
|
||||
EntityEnderman enderman = new EntityEnderman(worldObj);
|
||||
enderman.setLocationAndAngles(xCoord + 0.5, yCoord - 1, zCoord + 0.5, 5, 6);
|
||||
enderman.setLocationAndAngles(pos.getX() + 0.5, pos.getY() - 1, pos.getZ() + 0.5, 5, 6);
|
||||
worldObj.spawnEntityInWorld(enderman);
|
||||
|
||||
if (random.nextInt(MAX_HOSTILE_ENDERMAN_CHANCE) < HOSTILE_ENDERMAN_CHANCE)
|
||||
{
|
||||
if (random.nextInt(MAX_HOSTILE_ENDERMAN_CHANCE) < HOSTILE_ENDERMAN_CHANCE) {
|
||||
EntityPlayer player = this.worldObj.getClosestPlayerToEntity(enderman, 50);
|
||||
if (player != null)
|
||||
{
|
||||
enderman.setTarget(player);
|
||||
if (player != null) {
|
||||
enderman.setAttackTarget(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,41 +123,35 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
}
|
||||
}
|
||||
|
||||
private void closeRift()
|
||||
{
|
||||
private void closeRift() {
|
||||
NewDimData dimension = PocketManager.createDimensionData(worldObj);
|
||||
if (growth < CLOSING_PERIOD / 2)
|
||||
{
|
||||
for (DimLink riftLink : dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord))
|
||||
{
|
||||
if (growth < CLOSING_PERIOD / 2) {
|
||||
for (DimLink riftLink : dimension.findRiftsInRange(worldObj, 6, pos)) {
|
||||
Point4D location = riftLink.source();
|
||||
TileEntityRift rift = (TileEntityRift) worldObj.getTileEntity(location.getX(), location.getY(), location.getZ());
|
||||
if (rift != null && !rift.shouldClose)
|
||||
{
|
||||
TileEntityRift rift = (TileEntityRift) worldObj.getTileEntity(location.toBlockPos());
|
||||
if (rift != null && !rift.shouldClose) {
|
||||
rift.shouldClose = true;
|
||||
rift.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (growth <= 0 && !worldObj.isRemote)
|
||||
{
|
||||
DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj);
|
||||
if (link != null && !worldObj.isRemote)
|
||||
{
|
||||
if (growth <= 0 && !worldObj.isRemote) {
|
||||
DimLink link = PocketManager.getLink(pos, worldObj);
|
||||
if (link != null && !worldObj.isRemote) {
|
||||
dimension.deleteLink(link);
|
||||
}
|
||||
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
||||
worldObj.playSound(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "mods.DimDoors.sfx.riftClose", 0.7f, 1, false);
|
||||
|
||||
worldObj.setBlockToAir(pos);
|
||||
worldObj.playSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, "mods.DimDoors.sfx.riftClose", 0.7f, 1, false);
|
||||
}
|
||||
|
||||
growth --;
|
||||
}
|
||||
|
||||
public boolean updateNearestRift()
|
||||
{
|
||||
public boolean updateNearestRift() {
|
||||
Point4D previousNearest = nearestRiftLocation;
|
||||
DimLink nearestRiftLink = PocketManager.createDimensionData(worldObj).findNearestRift(
|
||||
worldObj, RIFT_INTERACTION_RANGE, xCoord, yCoord, zCoord);
|
||||
worldObj, RIFT_INTERACTION_RANGE, pos);
|
||||
|
||||
nearestRiftLocation = (nearestRiftLink == null) ? null : nearestRiftLink.source();
|
||||
|
||||
|
@ -188,73 +164,57 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
return (nearestRiftLocation != null);
|
||||
}
|
||||
|
||||
private void updateParticleOffsets()
|
||||
{
|
||||
if (nearestRiftLocation != null)
|
||||
{
|
||||
this.xOffset = this.xCoord - nearestRiftLocation.getX();
|
||||
this.yOffset = this.yCoord - nearestRiftLocation.getY();
|
||||
this.zOffset = this.zCoord - nearestRiftLocation.getZ();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.xOffset = 0;
|
||||
this.yOffset = 0;
|
||||
this.xOffset = 0;
|
||||
private void updateParticleOffsets() {
|
||||
if (nearestRiftLocation != null) {
|
||||
this.offset = this.pos.subtract(nearestRiftLocation.toBlockPos());
|
||||
} else {
|
||||
this.offset = BlockPos.ORIGIN;
|
||||
}
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass)
|
||||
{
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
return pass == 1;
|
||||
}
|
||||
|
||||
public int countAncestorLinks(DimLink link)
|
||||
{
|
||||
if (link.parent() != null)
|
||||
{
|
||||
public int countAncestorLinks(DimLink link) {
|
||||
if (link.parent() != null) {
|
||||
return countAncestorLinks(link.parent()) + 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void spread(DDProperties properties)
|
||||
{
|
||||
public void spread(DDProperties properties) {
|
||||
if (worldObj.isRemote || !properties.RiftSpreadEnabled
|
||||
|| random.nextInt(MAX_RIFT_SPREAD_CHANCE) < RIFT_SPREAD_CHANCE || this.shouldClose)
|
||||
{
|
||||
|| random.nextInt(MAX_RIFT_SPREAD_CHANCE) < RIFT_SPREAD_CHANCE || this.shouldClose) {
|
||||
return;
|
||||
}
|
||||
|
||||
NewDimData dimension = PocketManager.createDimensionData(worldObj);
|
||||
DimLink link = dimension.getLink(xCoord, yCoord, zCoord);
|
||||
DimLink link = dimension.getLink(pos);
|
||||
|
||||
if (link.childCount() >= MAX_CHILD_LINKS || countAncestorLinks(link) >= MAX_ANCESTOR_LINKS)
|
||||
{
|
||||
if (link.childCount() >= MAX_CHILD_LINKS || countAncestorLinks(link) >= MAX_ANCESTOR_LINKS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The probability of rifts trying to spread increases if more rifts are nearby.
|
||||
// Players should see rifts spread faster within clusters than at the edges of clusters.
|
||||
// Also, single rifts CANNOT spread.
|
||||
int nearRifts = dimension.findRiftsInRange(worldObj, RIFT_INTERACTION_RANGE, xCoord, yCoord, zCoord).size();
|
||||
if (nearRifts == 0 || random.nextInt(nearRifts) == 0)
|
||||
{
|
||||
int nearRifts = dimension.findRiftsInRange(worldObj, RIFT_INTERACTION_RANGE, pos).size();
|
||||
if (nearRifts == 0 || random.nextInt(nearRifts) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
DimDoors.blockRift.spreadRift(dimension, link, worldObj, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
this.updateTimer = nbt.getInteger("updateTimer");
|
||||
this.xOffset = nbt.getInteger("xOffset");
|
||||
this.yOffset = nbt.getInteger("yOffset");
|
||||
this.zOffset = nbt.getInteger("zOffset");
|
||||
this.offset = new BlockPos(nbt.getInteger("xOffset"), nbt.getInteger("yOffset"), nbt.getInteger("zOffset"));
|
||||
this.shouldClose = nbt.getBoolean("shouldClose");
|
||||
this.spawnedEndermenID = nbt.getInteger("spawnedEndermenID");
|
||||
this.riftRotation = nbt.getInteger("riftRotation");
|
||||
|
@ -267,9 +227,9 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("updateTimer", this.updateTimer);
|
||||
nbt.setInteger("xOffset", this.xOffset);
|
||||
nbt.setInteger("yOffset", this.yOffset);
|
||||
nbt.setInteger("zOffset", this.zOffset);
|
||||
nbt.setInteger("xOffset", this.offset.getX());
|
||||
nbt.setInteger("yOffset", this.offset.getY());
|
||||
nbt.setInteger("zOffset", this.offset.getZ());
|
||||
nbt.setBoolean("shouldClose", this.shouldClose);
|
||||
nbt.setInteger("spawnedEndermenID", this.spawnedEndermenID);
|
||||
nbt.setInteger("riftRotation", this.riftRotation);
|
||||
|
@ -278,26 +238,24 @@ public class TileEntityRift extends DDTileEntityBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
writeToNBT(tag);
|
||||
|
||||
if(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj)!=null)
|
||||
{
|
||||
ClientLinkData linkData = new ClientLinkData(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj));
|
||||
if(PocketManager.getLink(pos, worldObj)!=null) {
|
||||
ClientLinkData linkData = new ClientLinkData(PocketManager.getLink(pos, worldObj));
|
||||
|
||||
NBTTagCompound link = new NBTTagCompound();
|
||||
linkData.writeToNBT(link);
|
||||
|
||||
tag.setTag("Link", link);
|
||||
}
|
||||
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, tag);
|
||||
return new S35PacketUpdateTileEntity(this.pos, 0, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
NBTTagCompound tag = pkt.func_148857_g();
|
||||
NBTTagCompound tag = pkt.getNbtCompound();
|
||||
readFromNBT(tag);
|
||||
|
||||
if (tag.hasKey("Link")) {
|
||||
|
|
|
@ -4,26 +4,16 @@ import java.util.Random;
|
|||
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
|
||||
public class TileEntityTransTrapdoor extends DDTileEntityBase
|
||||
{
|
||||
@Override
|
||||
public boolean canUpdate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public class TileEntityTransTrapdoor extends DDTileEntityBase {
|
||||
|
||||
@Override
|
||||
public float[] getRenderColor(Random rand)
|
||||
{
|
||||
public float[] getRenderColor(Random rand) {
|
||||
float[] rgbaColor = {1,1,1,1};
|
||||
if (this.worldObj.provider.dimensionId == DimDoors.NETHER_DIMENSION_ID)
|
||||
{
|
||||
if (this.worldObj.provider.getDimensionId() == DimDoors.NETHER_DIMENSION_ID) {
|
||||
rgbaColor[0] = worldObj.rand.nextFloat() * 0.5F + 0.4F;
|
||||
rgbaColor[1] = worldObj.rand.nextFloat() * 0.05F;
|
||||
rgbaColor[2] = worldObj.rand.nextFloat() * 0.05F;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
rgbaColor[0] = worldObj.rand.nextFloat() * 0.5F + 0.1F;
|
||||
rgbaColor[1] = worldObj.rand.nextFloat() * 0.4F + 0.4F;
|
||||
rgbaColor[2] = worldObj.rand.nextFloat() * 0.6F + 0.5F;
|
||||
|
|
Loading…
Add table
Reference in a new issue