Implementing a way to handle rift-connections 001

Made a start
It doesn't compile yet
This commit is contained in:
Mathijs Riezebos 2017-01-12 01:11:55 +01:00
parent db809a8219
commit 1b2d4ad20a
6 changed files with 134 additions and 2 deletions

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gradle-project-properties>
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
<source-level>1.8</source-level>
<built-in-tasks>
<task>
<display-name>run</display-name>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gradle-project-properties>
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
<auxiliary>
<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/CommonProxy.java</file>
<file>file:/C:/Users/Gebruiker/Documents/GitHub/DimDoors/src/main/java/com/zixiken/dimdoors/ModelManager.java</file>
</group>
</open-files>
</auxiliary>
</gradle-project-properties>

View file

@ -1,5 +1,6 @@
package com.zixiken.dimdoors.tileentities;
import com.zixiken.dimdoors.world.RiftHandler;
import java.util.Random;
import net.minecraft.block.state.IBlockState;
@ -9,6 +10,10 @@ import net.minecraft.world.World;
public abstract class DDTileEntityBase extends TileEntity
{
public boolean isPaired = false;
public int riftID;
public int pairedRiftID;
/**
*
* @return an array of floats representing RGBA color where 1.0 = 255.
@ -19,4 +24,30 @@ public abstract class DDTileEntityBase extends TileEntity
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
return oldState.getBlock() != newSate.getBlock();
}
public void pair(int otherRiftID) {
RiftHandler rifthandler;
if (isPaired) {
if (otherRiftID == pairedRiftID) {
return;
}
else {
rifthandler.unpair(pairedRiftID);
}
}
pairedRiftID = otherRiftID;
rifthandler.pair(pairedRiftID, riftID);
isPaired = true;
}
public void unpair() {
RiftHandler rifthandler;
if (!isPaired) {
return;
}
else {
isPaired = false;
rifthandler.unpair(pairedRiftID);
}
}
}

View file

@ -17,7 +17,7 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32;
private static final int HOSTILE_ENDERMAN_CHANCE = 1;
private static final int MAX_HOSTILE_ENDERMAN_CHANCE = 3;
private static final int UPDATE_PERIOD = 200;
private static final int UPDATE_PERIOD = 200; //10 seconds
private static Random random = new Random();
@ -93,7 +93,7 @@ public class TileEntityRift extends DDTileEntityBase implements ITickable {
private void closeRift() {
world.setBlockToAir(pos);
growth--;
growth--; //@todo?
}
public boolean updateNearestRift() {

View file

@ -0,0 +1,30 @@
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);
}
}

View file

@ -0,0 +1,57 @@
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();
}
}
}