Connected Rift-Link system to rift registry- and saving- system
Merged functionality of "RiftHandler" class into "RiftRegistry" class Moved the "Location" class Why the RiftRegistry couples the Rift ID to the Rift **location** and the PocketRegistry couples the Pocket ID to the actual Pocket **instance**: -Each Rift is a Tile-Entity, which means that it has its infromation can be stored using the Tile-Entitiy's information saving system. -Each Pocket is barely more than an information storage container, which depends on having an external information saving system, which the PocketRegistry provides for it.
This commit is contained in:
parent
5c6fd1d1fa
commit
f68c9ec4a2
8 changed files with 117 additions and 121 deletions
|
@ -2,6 +2,20 @@
|
||||||
<gradle-project-properties>
|
<gradle-project-properties>
|
||||||
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
|
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
|
||||||
<auxiliary>
|
<auxiliary>
|
||||||
|
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||||
<editor-bookmarks lastBookmarkId="0" xmlns="http://www.netbeans.org/ns/editor-bookmarks/2"/>
|
<editor-bookmarks lastBookmarkId="0" xmlns="http://www.netbeans.org/ns/editor-bookmarks/2"/>
|
||||||
|
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||||
|
<group>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/shared/RiftRegistry.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/tileentities/DDTileEntityBase.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/shared/DDSavedData.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/DimDoors.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/server/DDProxyServer.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/shared/Pocket.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/DDProxyCommon.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/shared/RiftSavedData.java</file>
|
||||||
|
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/shared/Location.java</file>
|
||||||
|
</group>
|
||||||
|
</open-files>
|
||||||
</auxiliary>
|
</auxiliary>
|
||||||
</gradle-project-properties>
|
</gradle-project-properties>
|
||||||
|
|
|
@ -5,11 +5,9 @@
|
||||||
*/
|
*/
|
||||||
package com.zixiken.dimdoors.shared;
|
package com.zixiken.dimdoors.shared;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldSavedData;
|
import net.minecraft.world.WorldSavedData;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
60
src/main/java/com/zixiken/dimdoors/shared/Location.java
Normal file
60
src/main/java/com/zixiken/dimdoors/shared/Location.java
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package com.zixiken.dimdoors.shared;
|
||||||
|
|
||||||
|
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||||
|
import net.minecraft.nbt.NBTBase;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Robijnvogel
|
||||||
|
*/
|
||||||
|
public class Location {
|
||||||
|
|
||||||
|
public int dimensionID;
|
||||||
|
public BlockPos pos;
|
||||||
|
|
||||||
|
Location(int dimID, int x, int y, int z) {
|
||||||
|
this.dimensionID = dimID;
|
||||||
|
pos = new BlockPos(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Location(int dimID, BlockPos pos) {
|
||||||
|
this.dimensionID = dimID;
|
||||||
|
this.pos = pos.up(0); //copyOf
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileEntity getTileEntity() {
|
||||||
|
World world = DimensionManager.getWorld(dimensionID); //@todo HOW?
|
||||||
|
return world.getTileEntity(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Location getLocation(TileEntity tileEntity) {
|
||||||
|
World world = tileEntity.getWorld();
|
||||||
|
int dimID = world.provider.getDimension();
|
||||||
|
BlockPos blockPos = tileEntity.getPos();
|
||||||
|
return new Location(dimID, blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
static NBTBase writeToNBT(Location location) {
|
||||||
|
NBTTagCompound locationNBT = new NBTTagCompound();
|
||||||
|
locationNBT.setInteger("worldID", location.dimensionID);
|
||||||
|
locationNBT.setInteger("x", location.pos.getX());
|
||||||
|
locationNBT.setInteger("y", location.pos.getY());
|
||||||
|
locationNBT.setInteger("z", location.pos.getZ());
|
||||||
|
return locationNBT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Location readFromNBT(NBTTagCompound locationNBT) {
|
||||||
|
int worldID = locationNBT.getInteger("worldID");
|
||||||
|
int x = locationNBT.getInteger("x");
|
||||||
|
int y = locationNBT.getInteger("y");
|
||||||
|
int z = locationNBT.getInteger("z");
|
||||||
|
BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
|
return new Location(worldID, blockPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,10 +5,12 @@
|
||||||
*/
|
*/
|
||||||
package com.zixiken.dimdoors.shared;
|
package com.zixiken.dimdoors.shared;
|
||||||
|
|
||||||
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,30 +22,30 @@ public class RiftRegistry {
|
||||||
public static final RiftRegistry Instance = new RiftRegistry();
|
public static final RiftRegistry Instance = new RiftRegistry();
|
||||||
|
|
||||||
// Privates
|
// Privates
|
||||||
private int nextUnusedID;
|
private int nextRiftID;
|
||||||
private final Map<Integer, DDTileEntityBase> riftList;
|
private final Map<Integer, Location> riftList;
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
public RiftRegistry() {
|
public RiftRegistry() {
|
||||||
nextUnusedID = 0;
|
nextRiftID = 0;
|
||||||
riftList = new HashMap();
|
riftList = new HashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
nextUnusedID = 0;
|
nextRiftID = 0;
|
||||||
riftList.clear();
|
riftList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
nextUnusedID = nbt.getInteger("nextUnusedID");
|
nextRiftID = nbt.getInteger("nextUnusedID");
|
||||||
if (nbt.hasKey("riftData")) {
|
if (nbt.hasKey("riftData")) {
|
||||||
NBTTagCompound riftsNBT = nbt.getCompoundTag("riftData");
|
NBTTagCompound riftsNBT = nbt.getCompoundTag("riftData");
|
||||||
int i = 1;
|
int i = 1;
|
||||||
String tag = "" + i;
|
String tag = "" + i;
|
||||||
while (riftsNBT.hasKey(tag)) {
|
while (riftsNBT.hasKey(tag)) {
|
||||||
NBTTagCompound riftNBT = riftsNBT.getCompoundTag(tag);
|
NBTTagCompound riftNBT = riftsNBT.getCompoundTag(tag);
|
||||||
DDTileEntityBase rift = DDTileEntityBase.readFromNBT(i, riftNBT);
|
Location riftLocation = Location.readFromNBT(riftNBT);
|
||||||
riftList.put(i, rift);
|
riftList.put(i, riftLocation);
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
tag = "" + i;
|
tag = "" + i;
|
||||||
|
@ -52,30 +54,48 @@ public class RiftRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
nbt.setInteger("nextUnusedID", nextUnusedID);
|
nbt.setInteger("nextUnusedID", nextRiftID);
|
||||||
NBTTagCompound riftsNBT = new NBTTagCompound();
|
NBTTagCompound riftsNBT = new NBTTagCompound();
|
||||||
for (Map.Entry<Integer, DDTileEntityBase> entry : riftList.entrySet()) {
|
for (Map.Entry<Integer, Location> entry : riftList.entrySet()) {
|
||||||
riftsNBT.setTag("" + entry.getKey(), DDTileEntityBase.writeToNBT(entry.getValue()));
|
riftsNBT.setTag("" + entry.getKey(), Location.writeToNBT(entry.getValue()));
|
||||||
}
|
}
|
||||||
nbt.setTag("riftData", riftsNBT);
|
nbt.setTag("riftData", riftsNBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int registerNewRift(DDTileEntityBase rift, World world) {
|
public int registerNewRift(DDTileEntityBase rift) {
|
||||||
riftList.put(nextUnusedID, rift);
|
riftList.put(nextRiftID, Location.getLocation(rift));
|
||||||
|
|
||||||
nextUnusedID++;
|
nextRiftID++;
|
||||||
RiftSavedData.get(world).markDirty(); //Notify that this needs to be saved on world save
|
RiftSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||||
return nextUnusedID -1;
|
return nextRiftID -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRift(int riftID, World world) {
|
public void removeRift(int riftID, World world) {
|
||||||
if (riftList.containsKey(riftID)) {
|
if (riftList.containsKey(riftID)) {
|
||||||
riftList.remove(riftID);
|
riftList.remove(riftID);
|
||||||
RiftSavedData.get(world).markDirty(); //Notify that this needs to be saved on world save
|
RiftSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DDTileEntityBase getRift(int ID) {
|
public Location getRiftLocation(int ID) {
|
||||||
return riftList.get(ID);
|
return riftList.get(ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pair(int riftID, int riftID2) {
|
||||||
|
Location location = riftList.get(riftID);
|
||||||
|
TileEntity tileEntity = location.getTileEntity(); //@todo this method might need to be in another class?
|
||||||
|
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
||||||
|
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||||
|
rift.pair(riftID2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unpair(int riftID) {
|
||||||
|
Location location = riftList.get(riftID);
|
||||||
|
TileEntity tileEntity = location.getTileEntity();
|
||||||
|
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
||||||
|
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||||
|
rift.unpair();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
package com.zixiken.dimdoors.shared;
|
package com.zixiken.dimdoors.shared;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package com.zixiken.dimdoors.tileentities;
|
package com.zixiken.dimdoors.tileentities;
|
||||||
|
|
||||||
import com.zixiken.dimdoors.world.RiftHandler;
|
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -27,36 +25,30 @@ public abstract class DDTileEntityBase extends TileEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pair(int otherRiftID) {
|
public void pair(int otherRiftID) {
|
||||||
RiftHandler rifthandler;
|
|
||||||
if (isPaired) {
|
if (isPaired) {
|
||||||
if (otherRiftID == pairedRiftID) {
|
if (otherRiftID == pairedRiftID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rifthandler.unpair(pairedRiftID);
|
RiftRegistry.Instance.unpair(pairedRiftID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pairedRiftID = otherRiftID;
|
pairedRiftID = otherRiftID;
|
||||||
rifthandler.pair(pairedRiftID, riftID);
|
RiftRegistry.Instance.pair(pairedRiftID, riftID);
|
||||||
isPaired = true;
|
isPaired = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unpair() {
|
public void unpair() {
|
||||||
RiftHandler rifthandler;
|
|
||||||
if (!isPaired) {
|
if (!isPaired) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
isPaired = false;
|
isPaired = false;
|
||||||
rifthandler.unpair(pairedRiftID);
|
RiftRegistry.Instance.unpair(pairedRiftID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NBTTagCompound writeToNBT(DDTileEntityBase rift) {
|
private void register() {
|
||||||
|
riftID = RiftRegistry.Instance.registerNewRift(this);
|
||||||
}
|
|
||||||
|
|
||||||
public static DDTileEntityBase readFromNBT(int dim, NBTTagCompound riftNBT) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.zixiken.dimdoors.world;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Robijnvogel
|
|
||||||
*/
|
|
||||||
public class Location {
|
|
||||||
public String dimensionUID;
|
|
||||||
public BlockPos pos;
|
|
||||||
|
|
||||||
Location(String dimUID, int x, int y, int z) {
|
|
||||||
this.dimensionUID = dimUID;
|
|
||||||
pos = new BlockPos(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Location(String dimUID, BlockPos pos) {
|
|
||||||
this.dimensionUID = dimUID;
|
|
||||||
this.pos = pos.up(0); //copyOf
|
|
||||||
}
|
|
||||||
|
|
||||||
TileEntity getTileEntity() {
|
|
||||||
World world = getWorld(dimensionUID); //@todo HOW?
|
|
||||||
return world.getTileEntity(pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package com.zixiken.dimdoors.world;
|
|
||||||
|
|
||||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Robijnvogel
|
|
||||||
*/
|
|
||||||
public class RiftHandler {
|
|
||||||
private Map<Integer, Location> riftLocations; //it needs to be a Map if we want to be able to remove rifts without the IDs shifting (as would happen in a List
|
|
||||||
private int nextRiftID;
|
|
||||||
|
|
||||||
RiftHandler() { //@todo don't forget to create one object of this class at world-load
|
|
||||||
riftLocations = new HashMap<>();
|
|
||||||
nextRiftID = 0;
|
|
||||||
readfromNBT(); //and also add a method to write to NBT
|
|
||||||
}
|
|
||||||
|
|
||||||
public int addRift(Location location) {
|
|
||||||
int riftID = nextRiftID;
|
|
||||||
nextRiftID++;
|
|
||||||
riftLocations.put(riftID, location);
|
|
||||||
return riftID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeRift(int riftID, Location location) {
|
|
||||||
riftLocations.remove(riftID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation(int riftID) {
|
|
||||||
Location location = riftLocations.get(riftID);
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pair(int riftID, int riftID2) {
|
|
||||||
Location location = riftLocations.get(riftID);
|
|
||||||
TileEntity tileEntity = location.getTileEntity(); //@todo this method might need to be in another class?
|
|
||||||
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
|
||||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
|
||||||
rift.pair(riftID2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unpair(int riftID) {
|
|
||||||
Location location = riftLocations.get(riftID);
|
|
||||||
TileEntity tileEntity = location.getTileEntity();
|
|
||||||
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
|
||||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
|
||||||
rift.unpair();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue