Added connecting rifts
Changed the functioning of and registered the ItemRiftConnectionTool item. Repaired a stupid mistake in DDTileEntityBase
This commit is contained in:
parent
0c5ef6193c
commit
f93c4e3670
4 changed files with 69 additions and 33 deletions
|
@ -8,8 +8,10 @@ package com.zixiken.dimdoors.items;
|
||||||
import com.zixiken.dimdoors.DimDoors;
|
import com.zixiken.dimdoors.DimDoors;
|
||||||
import com.zixiken.dimdoors.shared.RiftRegistry;
|
import com.zixiken.dimdoors.shared.RiftRegistry;
|
||||||
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
import com.zixiken.dimdoors.tileentities.DDTileEntityBase;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -28,50 +30,72 @@ import net.minecraft.world.World;
|
||||||
*/
|
*/
|
||||||
public class ItemRiftConnectionTool extends ItemTool {
|
public class ItemRiftConnectionTool extends ItemTool {
|
||||||
|
|
||||||
ItemRiftConnectionTool(float attackDamageIn, float attackSpeedIn, Item.ToolMaterial materialIn, Set<Block> effectiveBlocksIn) {
|
public static final String ID = "itemRiftConnectionTool";
|
||||||
super(attackDamageIn, attackSpeedIn, materialIn, effectiveBlocksIn);
|
|
||||||
|
ItemRiftConnectionTool() {
|
||||||
|
super(1.0F, -2.8F, ToolMaterial.WOOD, new HashSet());
|
||||||
//@todo add extra stuff?
|
//@todo add extra stuff?
|
||||||
|
setUnlocalizedName(ID);
|
||||||
|
setRegistryName(ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
|
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
|
||||||
|
if (!stack.hasTagCompound()) {
|
||||||
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
compound.setBoolean("isInConnectMode", true);
|
||||||
|
stack.setTagCompound(compound);
|
||||||
|
}
|
||||||
|
|
||||||
RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
|
RayTraceResult hit = ItemDoorBase.doRayTrace(worldIn, playerIn, true);
|
||||||
if (hit != null) {
|
if (hit != null && worldIn.getTileEntity(hit.getBlockPos()) instanceof DDTileEntityBase) {
|
||||||
BlockPos pos = hit.getBlockPos();
|
DDTileEntityBase rift = (DDTileEntityBase) worldIn.getTileEntity(hit.getBlockPos());
|
||||||
if (worldIn.getTileEntity(pos) instanceof DDTileEntityBase) {
|
if (playerIn.isSneaking()) {
|
||||||
DDTileEntityBase rift = (DDTileEntityBase) worldIn.getTileEntity(pos);
|
return selectRift(stack, worldIn, rift, playerIn); //new ActionResult(EnumActionResult.PASS, stack));
|
||||||
if (!playerIn.isSneaking()) {
|
}
|
||||||
selectPrimaryRift(stack, rift);
|
|
||||||
} else {
|
} else {
|
||||||
selectSecondaryRiftAndTakeAction(stack, rift);
|
return changeMode(stack);
|
||||||
}
|
|
||||||
return new ActionResult(EnumActionResult.PASS, stack);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ActionResult(EnumActionResult.FAIL, stack);
|
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectPrimaryRift(ItemStack stack, DDTileEntityBase rift) {
|
private ActionResult<ItemStack> selectRift(ItemStack stack, World worldIn, DDTileEntityBase rift, EntityPlayer playerIn) {
|
||||||
|
DimDoors.log(this.getClass(), "Selecting rift with ID: " + rift.riftID);
|
||||||
NBTTagCompound compound = stack.getTagCompound();
|
NBTTagCompound compound = stack.getTagCompound();
|
||||||
compound.setInteger("primaryRiftID", rift.riftID);
|
if (compound.getBoolean("isInConnectMode")) {
|
||||||
|
if (compound.hasKey("RiftID")) {
|
||||||
|
int primaryRiftID = compound.getInteger("RiftID");
|
||||||
|
int secondaryRiftID = rift.riftID;
|
||||||
|
if (!worldIn.isRemote) {
|
||||||
|
DimDoors.log(this.getClass(), "Pairing rifts with IDs: " + primaryRiftID + " and " + secondaryRiftID);
|
||||||
|
RiftRegistry.Instance.pair(primaryRiftID, secondaryRiftID);
|
||||||
|
}
|
||||||
|
compound.removeTag("RiftID");
|
||||||
|
stack.damageItem(1, playerIn);
|
||||||
|
} else {
|
||||||
|
compound.setInteger("RiftID", rift.riftID);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!worldIn.isRemote) {
|
||||||
|
RiftRegistry.Instance.unpair(rift.riftID);
|
||||||
|
}
|
||||||
|
stack.damageItem(1, playerIn);
|
||||||
|
}
|
||||||
|
return new ActionResult(EnumActionResult.SUCCESS, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectSecondaryRiftAndTakeAction(ItemStack stack, DDTileEntityBase rift) {
|
private ActionResult<ItemStack> changeMode(ItemStack stack) {
|
||||||
NBTTagCompound compound = stack.getTagCompound();
|
NBTTagCompound compound = stack.getTagCompound();
|
||||||
if (!compound.hasKey("isInConnectMode")) {
|
if (compound.getBoolean("isInConnectMode")) {
|
||||||
|
compound.setBoolean("isInConnectMode", false);
|
||||||
|
if (compound.hasKey("RiftID")) {
|
||||||
|
compound.removeTag("RiftID");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
compound.setBoolean("isInConnectMode", true);
|
compound.setBoolean("isInConnectMode", true);
|
||||||
}
|
}
|
||||||
if (compound.getBoolean("isInConnectMode")) {
|
DimDoors.log(this.getClass(), "isInConnectMode set to: " + compound.getBoolean("isInConnectMode"));
|
||||||
if (compound.hasKey("primaryRiftID")) {
|
return new ActionResult(EnumActionResult.SUCCESS, stack);
|
||||||
int primaryRiftID = compound.getInteger("primaryRiftID");
|
|
||||||
int secondaryRiftID = rift.riftID;
|
|
||||||
RiftRegistry.Instance.pair(primaryRiftID, secondaryRiftID);
|
|
||||||
} else {
|
|
||||||
DimDoors.log(this.getClass(), "Primary Rift not selected. First select a primary rift by right-clicking without sneaking.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int secondaryRiftID = rift.riftID;
|
|
||||||
RiftRegistry.Instance.unpair(secondaryRiftID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class ModItems {
|
||||||
public static ItemDoorQuartz itemDoorQuartz;
|
public static ItemDoorQuartz itemDoorQuartz;
|
||||||
public static ItemDimDoorPersonal itemDimDoorPersonal;
|
public static ItemDimDoorPersonal itemDimDoorPersonal;
|
||||||
public static ItemBlockDimWall itemBlockDimWall;
|
public static ItemBlockDimWall itemBlockDimWall;
|
||||||
|
public static ItemRiftConnectionTool itemRiftConnectionTool;
|
||||||
|
|
||||||
public static void registerItems() {
|
public static void registerItems() {
|
||||||
GameRegistry.register(itemDoorQuartz = new ItemDoorQuartz());
|
GameRegistry.register(itemDoorQuartz = new ItemDoorQuartz());
|
||||||
|
@ -27,6 +28,7 @@ public class ModItems {
|
||||||
GameRegistry.register(itemStableFabric = new ItemStableFabric());
|
GameRegistry.register(itemStableFabric = new ItemStableFabric());
|
||||||
GameRegistry.register(itemDimDoorChaos = new ItemDimDoorUnstable());
|
GameRegistry.register(itemDimDoorChaos = new ItemDimDoorUnstable());
|
||||||
GameRegistry.register(itemWorldThread = new ItemWorldThread());
|
GameRegistry.register(itemWorldThread = new ItemWorldThread());
|
||||||
|
GameRegistry.register(itemRiftConnectionTool = new ItemRiftConnectionTool());
|
||||||
|
|
||||||
//ItemBlocks
|
//ItemBlocks
|
||||||
GameRegistry.register(itemBlockDimWall = new ItemBlockDimWall());
|
GameRegistry.register(itemBlockDimWall = new ItemBlockDimWall());
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class RiftRegistry {
|
||||||
nextRiftID = 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 = 0;
|
||||||
String tag = "" + i;
|
String tag = "" + i;
|
||||||
while (riftsNBT.hasKey(tag)) {
|
while (riftsNBT.hasKey(tag)) {
|
||||||
NBTTagCompound riftNBT = riftsNBT.getCompoundTag(tag);
|
NBTTagCompound riftNBT = riftsNBT.getCompoundTag(tag);
|
||||||
|
@ -66,13 +66,13 @@ public class RiftRegistry {
|
||||||
|
|
||||||
public int registerNewRift(DDTileEntityBase rift) {
|
public int registerNewRift(DDTileEntityBase rift) {
|
||||||
riftList.put(nextRiftID, Location.getLocation(rift));
|
riftList.put(nextRiftID, Location.getLocation(rift));
|
||||||
//DimDoors.log("Rift registered as ID: " + nextRiftID);
|
DimDoors.log(this.getClass(), "Rift registered as ID: " + nextRiftID);
|
||||||
nextRiftID++;
|
nextRiftID++;
|
||||||
RiftSavedData.get(DimDoors.getDefWorld()).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 nextRiftID - 1;
|
return nextRiftID - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRift(int riftID, World world) {
|
public void unregisterRift(int riftID, World world) {
|
||||||
if (riftList.containsKey(riftID)) {
|
if (riftList.containsKey(riftID)) {
|
||||||
riftList.remove(riftID);
|
riftList.remove(riftID);
|
||||||
RiftSavedData.get(DimDoors.getDefWorld()).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
|
||||||
|
@ -84,6 +84,10 @@ public class RiftRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pair(int riftID, int riftID2) {
|
public void pair(int riftID, int riftID2) {
|
||||||
|
if (riftID < 0 || riftID2 < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DimDoors.log(this.getClass(), "pairing rift with ID " + riftID + " to rift with ID " + riftID2);
|
||||||
Location location = riftList.get(riftID);
|
Location location = riftList.get(riftID);
|
||||||
TileEntity tileEntity = location.getTileEntity(); //@todo this method might need to be in another class?
|
TileEntity tileEntity = location.getTileEntity(); //@todo this method might need to be in another class?
|
||||||
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
||||||
|
@ -93,7 +97,13 @@ public class RiftRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unpair(int riftID) {
|
public void unpair(int riftID) {
|
||||||
|
if (riftID < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Location location = riftList.get(riftID);
|
Location location = riftList.get(riftID);
|
||||||
|
if (location == null) {
|
||||||
|
DimDoors.log(this.getClass(), "riftID with null location = " + riftID);
|
||||||
|
}
|
||||||
TileEntity tileEntity = location.getTileEntity();
|
TileEntity tileEntity = location.getTileEntity();
|
||||||
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
if (tileEntity != null && tileEntity instanceof DDTileEntityBase) {
|
||||||
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
DDTileEntityBase rift = (DDTileEntityBase) tileEntity;
|
||||||
|
|
|
@ -34,8 +34,8 @@ public abstract class DDTileEntityBase extends TileEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pairedRiftID = otherRiftID;
|
pairedRiftID = otherRiftID;
|
||||||
RiftRegistry.Instance.pair(pairedRiftID, riftID);
|
|
||||||
isPaired = true;
|
isPaired = true;
|
||||||
|
RiftRegistry.Instance.pair(pairedRiftID, riftID);
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue