mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Merge pull request #2250 from MellowArpeggiation/master
Nodespace performance improvements MkII
This commit is contained in:
commit
3592deca8e
@ -1,6 +0,0 @@
|
||||
package com.hbm.interfaces;
|
||||
|
||||
public interface IAnimatedDoor extends IDoor {
|
||||
|
||||
public void handleNewState(byte state);
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package com.hbm.interfaces;
|
||||
|
||||
public interface IDoor {
|
||||
|
||||
void open();
|
||||
void close();
|
||||
DoorState getState();
|
||||
void toggle();
|
||||
default boolean setTexture(String tex) {
|
||||
return false;
|
||||
}
|
||||
default void setTextureState(byte tex) { }
|
||||
|
||||
default boolean setSkinIndex(byte skinIndex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
enum DoorState {
|
||||
CLOSED,
|
||||
OPEN,
|
||||
CLOSING,
|
||||
OPENING
|
||||
}
|
||||
}
|
||||
@ -53,8 +53,6 @@ public class PacketDispatcher {
|
||||
wrapper.registerMessage(NBTControlPacket.Handler.class, NBTControlPacket.class, i++, Side.SERVER);
|
||||
//Packet to send for anvil recipes to be crafted
|
||||
wrapper.registerMessage(AnvilCraftPacket.Handler.class, AnvilCraftPacket.class, i++, Side.SERVER);
|
||||
//Sends a funi text to display like a music disc announcement
|
||||
wrapper.registerMessage(TEDoorAnimationPacket.Handler.class, TEDoorAnimationPacket.class, i++, Side.CLIENT);
|
||||
//Does ExVNT standard player knockback
|
||||
wrapper.registerMessage(ExplosionKnockbackPacket.Handler.class, ExplosionKnockbackPacket.class, i++, Side.CLIENT);
|
||||
//just go fuck yourself already
|
||||
|
||||
@ -1,77 +0,0 @@
|
||||
package com.hbm.packet.toclient;
|
||||
|
||||
import com.hbm.interfaces.IAnimatedDoor;
|
||||
|
||||
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 cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class TEDoorAnimationPacket implements IMessage {
|
||||
|
||||
public int x, y, z;
|
||||
public byte state;
|
||||
public byte skinIndex;
|
||||
public byte texture;
|
||||
|
||||
public TEDoorAnimationPacket() {
|
||||
}
|
||||
|
||||
public TEDoorAnimationPacket(int x, int y, int z, byte state) {
|
||||
this(x, y, z, state, (byte) 0, (byte) -1);
|
||||
}
|
||||
|
||||
public TEDoorAnimationPacket(int x, int y, int z, byte state, byte skinIndex, byte tex) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.state = state;
|
||||
this.skinIndex = skinIndex;
|
||||
this.texture = tex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
state = buf.readByte();
|
||||
skinIndex = buf.readByte();
|
||||
if(buf.readableBytes() == 1){
|
||||
texture = buf.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeByte(state);
|
||||
buf.writeByte(skinIndex);
|
||||
if(texture != -1){
|
||||
buf.writeByte(texture);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<TEDoorAnimationPacket, IMessage> {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IMessage onMessage(TEDoorAnimationPacket m, MessageContext ctx) {
|
||||
|
||||
TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z);
|
||||
if(te instanceof IAnimatedDoor){
|
||||
((IAnimatedDoor) te).handleNewState(m.state);
|
||||
((IAnimatedDoor) te).setSkinIndex(m.skinIndex);
|
||||
((IAnimatedDoor) te).setTextureState(m.texture);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,25 +6,22 @@ import java.util.Set;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.blocks.generic.BlockDoorGeneric;
|
||||
import com.hbm.interfaces.IAnimatedDoor;
|
||||
import com.hbm.lib.Library;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.packet.toclient.TEDoorAnimationPacket;
|
||||
import com.hbm.sound.AudioWrapper;
|
||||
import com.hbm.tileentity.machine.TileEntityLockableBase;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
import com.hbm.util.fauxpointtwelve.Rotation;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAnimatedDoor {
|
||||
public class TileEntityDoorGeneric extends TileEntityLockableBase {
|
||||
|
||||
//0: closed, 1: open, 2: closing, 3: opening
|
||||
public byte state = 0;
|
||||
@ -39,9 +36,9 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
|
||||
private AudioWrapper audio;
|
||||
private AudioWrapper audio2;
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity(){
|
||||
public void updateEntity() {
|
||||
if(state == 3) {
|
||||
openTicks++;
|
||||
if(openTicks >= getDoorType().timeToOpen()) {
|
||||
@ -55,39 +52,39 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
}
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
|
||||
BlockPos pos = new BlockPos(this);
|
||||
|
||||
|
||||
int[][] ranges = getDoorType().getDoorOpenRanges();
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata() - BlockDummyable.offset);
|
||||
|
||||
|
||||
if(state == 3) {
|
||||
|
||||
|
||||
for(int i = 0; i < ranges.length; i++) {
|
||||
|
||||
|
||||
int[] range = ranges[i];
|
||||
BlockPos startPos = new BlockPos(range[0], range[1], range[2]);
|
||||
float time = getDoorType().getDoorRangeOpenTime(openTicks, i);
|
||||
|
||||
|
||||
for(int j = 0; j < Math.abs(range[3]); j++) {
|
||||
|
||||
|
||||
if((float)j / (Math.abs(range[3] - 1)) > time)
|
||||
break;
|
||||
|
||||
|
||||
for(int k = 0; k < range[4]; k++) {
|
||||
BlockPos add = new BlockPos(0, 0, 0);
|
||||
switch(range[5]){
|
||||
switch(range[5]) {
|
||||
case 0: add = new BlockPos(0, k, (int)Math.signum(range[3]) * j); break;
|
||||
case 1: add = new BlockPos(k, (int)Math.signum(range[3]) * j, 0); break;
|
||||
case 2: add = new BlockPos((int)Math.signum(range[3]) * j, k, 0); break;
|
||||
}
|
||||
|
||||
|
||||
Rotation r = Rotation.getBlockRotation(dir);
|
||||
if(dir == Library.POS_X || dir == Library.NEG_X)
|
||||
r = r.add(Rotation.CLOCKWISE_180);
|
||||
|
||||
|
||||
BlockPos finalPos = startPos.add(add).rotate(r).add(pos);
|
||||
|
||||
|
||||
if(finalPos.equals(pos)) {
|
||||
this.shouldUseBB = false;
|
||||
} else {
|
||||
@ -96,24 +93,24 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if(state == 2){
|
||||
|
||||
|
||||
} else if(state == 2) {
|
||||
|
||||
for(int i = 0; i < ranges.length; i++) {
|
||||
|
||||
|
||||
int[] range = ranges[i];
|
||||
|
||||
BlockPos startPos = new BlockPos(range[0], range[1], range[2]);
|
||||
float time = getDoorType().getDoorRangeOpenTime(openTicks, i);
|
||||
|
||||
|
||||
for(int j = Math.abs(range[3])-1; j >= 0; j--) {
|
||||
|
||||
|
||||
if((float)j / (Math.abs(range[3] - 1)) < time)
|
||||
break;
|
||||
|
||||
|
||||
for(int k = 0; k < range[4]; k++) {
|
||||
BlockPos add = new BlockPos(0, 0, 0);
|
||||
switch(range[5]){
|
||||
switch(range[5]) {
|
||||
case 0: add = new BlockPos(0, k, (int)Math.signum(range[3]) * j); break;
|
||||
case 1: add = new BlockPos(k, (int)Math.signum(range[3]) * j, 0); break;
|
||||
case 2: add = new BlockPos((int)Math.signum(range[3]) * j, k, 0); break;
|
||||
@ -122,9 +119,9 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
Rotation r = Rotation.getBlockRotation(dir);
|
||||
if(dir == Library.POS_X || dir == Library.NEG_X)
|
||||
r = r.add(Rotation.CLOCKWISE_180);
|
||||
|
||||
|
||||
BlockPos finalPos = startPos.add(add).rotate(r).add(pos);
|
||||
|
||||
|
||||
if(finalPos.equals(pos)) {
|
||||
this.shouldUseBB = false;
|
||||
} else {
|
||||
@ -140,19 +137,34 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
if(state == 2 && openTicks == 0) {
|
||||
state = 0;
|
||||
}
|
||||
PacketDispatcher.wrapper.sendToAllAround(new TEDoorAnimationPacket(xCoord, yCoord, zCoord, state, skinIndex, (byte)(shouldUseBB ? 1 : 0)), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 100));
|
||||
|
||||
if(redstonePower == -1 && state == 1){
|
||||
|
||||
this.networkPackNT(100);
|
||||
|
||||
if(redstonePower == -1 && state == 1) {
|
||||
tryToggle(-1);
|
||||
} else if(redstonePower > 0 && state == 0){
|
||||
} else if(redstonePower > 0 && state == 0) {
|
||||
tryToggle(-1);
|
||||
}
|
||||
if(redstonePower == -1){
|
||||
if(redstonePower == -1) {
|
||||
redstonePower = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf) {
|
||||
buf.writeByte(state);
|
||||
buf.writeByte(skinIndex);
|
||||
buf.writeBoolean(shouldUseBB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(ByteBuf buf) {
|
||||
handleNewState(buf.readByte());
|
||||
setSkinIndex(buf.readByte());
|
||||
shouldUseBB = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
if(audio != null) {
|
||||
@ -164,20 +176,20 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
audio2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
public DoorDecl getDoorType(){
|
||||
|
||||
|
||||
public DoorDecl getDoorType() {
|
||||
|
||||
if(this.doorType == null && this.getBlockType() instanceof BlockDoorGeneric)
|
||||
this.doorType = ((BlockDoorGeneric)this.getBlockType()).type;
|
||||
|
||||
|
||||
return this.doorType;
|
||||
}
|
||||
|
||||
public boolean tryToggle(EntityPlayer player){
|
||||
|
||||
public boolean tryToggle(EntityPlayer player) {
|
||||
|
||||
if(this.isLocked() && player == null) return false;
|
||||
|
||||
if(state == 0 && redstonePower > 0){
|
||||
|
||||
if(state == 0 && redstonePower > 0) {
|
||||
//Redstone "power locks" doors, just like minecraft iron doors
|
||||
return false;
|
||||
}
|
||||
@ -194,8 +206,8 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tryToggle(int passcode){
|
||||
|
||||
public boolean tryToggle(int passcode) {
|
||||
if(this.isLocked() && passcode != this.lock)
|
||||
return false;
|
||||
if(this.state == 0) {
|
||||
@ -212,55 +224,28 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(){
|
||||
if(state == 0)
|
||||
toggle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
if(state == 1)
|
||||
toggle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoorState getState(){
|
||||
return DoorState.values()[state];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggle(){
|
||||
if(state == 0) {
|
||||
state = 3;
|
||||
} else if(state == 1) {
|
||||
state = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void handleNewState(byte state){
|
||||
|
||||
public void handleNewState(byte state) {
|
||||
|
||||
if(this.state != state) {
|
||||
DoorDecl doorType = getDoorType();
|
||||
|
||||
if(this.state == 0 && state == 3){ // Door transitioning to open
|
||||
if(this.state == 0 && state == 3) { // Door transitioning to open
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio.setKeepAlive(0);
|
||||
}
|
||||
|
||||
if(doorType.getOpenSoundLoop() != null){
|
||||
if(doorType.getOpenSoundLoop() != null) {
|
||||
audio = MainRegistry.proxy.getLoopedSound(doorType.getOpenSoundLoop(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
audio.startSound();
|
||||
}
|
||||
|
||||
if(doorType.getOpenSoundStart() != null){
|
||||
if(doorType.getOpenSoundStart() != null) {
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getOpenSoundStart(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
|
||||
if(doorType.getSoundLoop2() != null){
|
||||
if(doorType.getSoundLoop2() != null) {
|
||||
if(audio2 != null) audio2.stopSound();
|
||||
|
||||
audio2 = MainRegistry.proxy.getLoopedSound(doorType.getSoundLoop2(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
@ -268,21 +253,21 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
}
|
||||
}
|
||||
|
||||
if(this.state == 1 && state == 2){ // Door transitioning to closed
|
||||
if(this.state == 1 && state == 2) { // Door transitioning to closed
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
}
|
||||
|
||||
if(doorType.getCloseSoundLoop() != null){
|
||||
if(doorType.getCloseSoundLoop() != null) {
|
||||
audio = MainRegistry.proxy.getLoopedSound(doorType.getCloseSoundLoop(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
audio.startSound();
|
||||
}
|
||||
|
||||
if(doorType.getCloseSoundStart() != null){
|
||||
if(doorType.getCloseSoundStart() != null) {
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getCloseSoundStart(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
|
||||
if(doorType.getSoundLoop2() != null){
|
||||
if(doorType.getSoundLoop2() != null) {
|
||||
if(audio2 != null) audio2.stopSound();
|
||||
|
||||
audio2 = MainRegistry.proxy.getLoopedSound(doorType.getSoundLoop2(), xCoord, yCoord, zCoord, doorType.getSoundVolume(), 10F, 1F);
|
||||
@ -290,47 +275,39 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
}
|
||||
}
|
||||
|
||||
if(state == 1 || state == 0){ // Door finished any transition
|
||||
if(audio != null){
|
||||
if(state == 1 || state == 0) { // Door finished any transition
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
audio = null;
|
||||
}
|
||||
if(audio2 != null){
|
||||
if(audio2 != null) {
|
||||
audio2.stopSound();
|
||||
audio2 = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.state == 3 && state == 1){ // Door finished transitioning to open
|
||||
if(doorType.getOpenSoundEnd() != null){
|
||||
if(this.state == 3 && state == 1) { // Door finished transitioning to open
|
||||
if(doorType.getOpenSoundEnd() != null) {
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getOpenSoundEnd(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.state == 2 && state == 0){ // Door finished transitioning to closed
|
||||
if(doorType.getCloseSoundEnd() != null){
|
||||
if(this.state == 2 && state == 0) { // Door finished transitioning to closed
|
||||
if(doorType.getCloseSoundEnd() != null) {
|
||||
worldObj.playSound(xCoord, yCoord, zCoord, doorType.getCloseSoundEnd(), doorType.getSoundVolume(), 1F, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.state = state;
|
||||
if(state > 1)
|
||||
animStartTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
//Ah yes piggy backing on this packet
|
||||
@Override
|
||||
public void setTextureState(byte tex){
|
||||
shouldUseBB = tex > 0;
|
||||
|
||||
this.state = state;
|
||||
if(state > 1) animStartTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSkinIndex() {
|
||||
return skinIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSkinIndex(byte skinIndex) {
|
||||
if(!getDoorType().hasSkins())
|
||||
return false;
|
||||
@ -342,12 +319,12 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox(){
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return INFINITE_EXTENT_AABB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxRenderDistanceSquared(){
|
||||
public double getMaxRenderDistanceSquared() {
|
||||
return 65536D;
|
||||
}
|
||||
|
||||
@ -388,14 +365,14 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
}
|
||||
tag.setTag("activatedBlocks", activatedBlocks);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void validate(){
|
||||
public void validate() {
|
||||
super.validate();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void invalidate(){
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
if(audio != null) {
|
||||
audio.stopSound();
|
||||
@ -412,16 +389,16 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
boolean powered = worldObj.isBlockIndirectlyGettingPowered(x, y, z);
|
||||
boolean contained = activatedBlocks.contains(pos);
|
||||
if(!contained && powered){
|
||||
if(!contained && powered) {
|
||||
activatedBlocks.add(pos);
|
||||
if(redstonePower == -1){
|
||||
if(redstonePower == -1) {
|
||||
redstonePower = 0;
|
||||
}
|
||||
redstonePower++;
|
||||
} else if(contained && !powered){
|
||||
} else if(contained && !powered) {
|
||||
activatedBlocks.remove(pos);
|
||||
redstonePower--;
|
||||
if(redstonePower == 0){
|
||||
if(redstonePower == 0) {
|
||||
redstonePower = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.hbm.uninos;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -21,16 +22,16 @@ import net.minecraft.world.World;
|
||||
* @author hbm
|
||||
*/
|
||||
public class UniNodespace {
|
||||
|
||||
|
||||
public static HashMap<World, UniNodeWorld> worlds = new HashMap();
|
||||
public static Set<NodeNet> activeNodeNets = new HashSet();
|
||||
|
||||
|
||||
public static GenNode getNode(World world, int x, int y, int z, INetworkProvider type) {
|
||||
UniNodeWorld nodeWorld = worlds.get(world);
|
||||
if(nodeWorld != null) return nodeWorld.nodes.get(new Pair(new BlockPos(x, y, z), type));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static void createNode(World world, GenNode node) {
|
||||
UniNodeWorld nodeWorld = worlds.get(world);
|
||||
if(nodeWorld == null) {
|
||||
@ -39,21 +40,21 @@ public class UniNodespace {
|
||||
}
|
||||
nodeWorld.pushNode(node);
|
||||
}
|
||||
|
||||
|
||||
public static void destroyNode(World world, int x, int y, int z, INetworkProvider type) {
|
||||
GenNode node = getNode(world, x, y, z, type);
|
||||
if(node != null) {
|
||||
worlds.get(world).popNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void updateNodespace() {
|
||||
|
||||
|
||||
for(World world : MinecraftServer.getServer().worldServers) {
|
||||
UniNodeWorld nodeWorld = worlds.get(world);
|
||||
|
||||
if(nodeWorld == null) continue;
|
||||
|
||||
|
||||
for(Entry<Pair<BlockPos, INetworkProvider>, GenNode> entry : nodeWorld.nodes.entrySet()) {
|
||||
GenNode node = entry.getValue();
|
||||
INetworkProvider provider = entry.getKey().getValue();
|
||||
@ -63,19 +64,19 @@ public class UniNodespace {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updateNetworks();
|
||||
}
|
||||
|
||||
|
||||
private static void updateNetworks() {
|
||||
|
||||
for(NodeNet net : activeNodeNets) net.resetTrackers(); //reset has to be done before everything else
|
||||
for(NodeNet net : activeNodeNets) net.update();
|
||||
}
|
||||
|
||||
|
||||
/** Goes over each connection point of the given node, tries to find neighbor nodes and to join networks with them */
|
||||
private static void checkNodeConnection(World world, GenNode node, INetworkProvider provider) {
|
||||
|
||||
|
||||
for(DirPos con : node.connections) {
|
||||
GenNode conNode = getNode(world, con.getX(), con.getY(), con.getZ(), provider); // get whatever neighbor node intersects with that connection
|
||||
if(conNode != null) { // if there is a node at that place
|
||||
@ -85,10 +86,10 @@ public class UniNodespace {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(node.net == null || !node.net.isValid()) provider.provideNetwork().joinLink(node);
|
||||
}
|
||||
|
||||
|
||||
/** Checks if the node can be connected to given the DirPos, skipSideCheck will ignore the DirPos' direction value */
|
||||
public static boolean checkConnection(GenNode connectsTo, DirPos connectFrom, boolean skipSideCheck) {
|
||||
for(DirPos revCon : connectsTo.connections) {
|
||||
@ -98,10 +99,10 @@ public class UniNodespace {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** Links two nodes with different or potentially no networks */
|
||||
private static void connectToNode(GenNode origin, GenNode connection) {
|
||||
|
||||
|
||||
if(origin.hasValidNet() && connection.hasValidNet()) { // both nodes have nets, but the nets are different (previous assumption), join networks
|
||||
if(origin.net.links.size() > connection.net.links.size()) {
|
||||
origin.net.joinNetworks(connection.net);
|
||||
@ -114,18 +115,18 @@ public class UniNodespace {
|
||||
origin.net.joinLink(connection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class UniNodeWorld {
|
||||
|
||||
public HashMap<Pair<BlockPos, INetworkProvider>, GenNode> nodes = new HashMap();
|
||||
|
||||
|
||||
public HashMap<Pair<BlockPos, INetworkProvider>, GenNode> nodes = new LinkedHashMap<>();
|
||||
|
||||
/** Adds a node at all its positions to the nodespace */
|
||||
public void pushNode(GenNode node) {
|
||||
for(BlockPos pos : node.positions) {
|
||||
nodes.put(new Pair(pos, node.networkProvider), node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Removes the specified node from all positions from nodespace */
|
||||
public void popNode(GenNode node) {
|
||||
if(node.net != null) node.net.destroy();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user