diff --git a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBTProcessor.java b/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBTProcessor.java index 98234763..746f480c 100644 --- a/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBTProcessor.java +++ b/AnnotatedNBT/src/main/java/org/dimdev/ddutils/nbt/SavedToNBTProcessor.java @@ -32,6 +32,7 @@ public class SavedToNBTProcessor extends AbstractProcessor { private static final String NBT_STORABLE = "org.dimdev.ddutils.nbt.INBTStorable"; private static final String VEC_3I = "net.minecraft.util.math.Vec3i"; private static final String LOCATION = "org.dimdev.ddutils.Location"; + private static final String RGBA = "org.dimdev.ddutils.RGBA"; private static final String VIRTUAL_LOCATION = "org.dimdev.dimdoors.shared.VirtualLocation"; private static final String UUID = "java.util.UUID"; @@ -307,6 +308,12 @@ public class SavedToNBTProcessor extends AbstractProcessor { w.println(nbt + ".setInteger(\"x\", " + from + ".getX());"); w.println(nbt + ".setInteger(\"y\", " + from + ".getY());"); w.println(nbt + ".setInteger(\"z\", " + from + ".getZ());"); + } else if (types.isAssignable(type, elements.getTypeElement(RGBA).asType())) { + w.println("NBTTagCompound " + nbt + " = new NBTTagCompound();"); + w.println(nbt + ".setFloat(\"red\", " + from + ".getRed());"); + w.println(nbt + ".setFloat(\"green\", " + from + ".getGreen());"); + w.println(nbt + ".setFloat(\"blue\", " + from + ".getBlue());"); + w.println(nbt + ".setFloat(\"alpha\", " + from + ".getAlpha());"); } else if (types.isAssignable(type, elements.getTypeElement(VIRTUAL_LOCATION).asType())) { w.println("NBTTagCompound " + nbt + " = new NBTTagCompound();"); w.println(nbt + ".setInteger(\"dim\", " + from + ".getDim());"); @@ -566,10 +573,16 @@ public class SavedToNBTProcessor extends AbstractProcessor { + "((NBTTagCompound) "+ nbt + ").getInteger(\"z\")" + ");"); } else if (types.isAssignable(type, elements.getTypeElement(LOCATION).asType())) { w.println(type + " " + to + " = new " + type + "(" - + "((NBTTagCompound) "+ nbt + ").getInteger(\"dim\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"x\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"y\"), " - + "((NBTTagCompound) "+ nbt + ").getInteger(\"z\")" + ");"); + + "((NBTTagCompound) "+ nbt + ").getInteger(\"dim\"), " + + "((NBTTagCompound) "+ nbt + ").getInteger(\"x\"), " + + "((NBTTagCompound) "+ nbt + ").getInteger(\"y\"), " + + "((NBTTagCompound) "+ nbt + ").getInteger(\"z\")" + ");"); + } else if (types.isAssignable(type, elements.getTypeElement(RGBA).asType())) { + w.println(type + " " + to + " = new " + type + "(" + + "((NBTTagCompound) "+ nbt + ").getFloat(\"red\"), " + + "((NBTTagCompound) "+ nbt + ").getFloat(\"green\"), " + + "((NBTTagCompound) "+ nbt + ").getFloat(\"blue\"), " + + "((NBTTagCompound) "+ nbt + ").getFloat(\"alpha\")" + ");"); } else if (types.isAssignable(type, elements.getTypeElement(VIRTUAL_LOCATION).asType())) { w.println(type + " " + to + " = new " + type + "(" + "((NBTTagCompound) "+ nbt + ").getInteger(\"dim\"), " diff --git a/build.gradle b/build.gradle index 52ffb9d4..ea71571e 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: 'net.minecraftforge.gradle.forge' // Version info String baseversion = "3.0.0" // Set beta to 0 after changing this -int beta = 2 // Set this to 0 for a non-beta release +int beta = 3 // Set this to 0 for a non-beta release ext.mcversion = "1.12.2" ext.forgeversion = "14.23.1.2555" String mcpversion = "snapshot_20171007" diff --git a/src/main/java/org/dimdev/ddutils/render/RGBA.java b/src/main/java/org/dimdev/ddutils/RGBA.java similarity index 76% rename from src/main/java/org/dimdev/ddutils/render/RGBA.java rename to src/main/java/org/dimdev/ddutils/RGBA.java index 51f218fa..7812bc79 100644 --- a/src/main/java/org/dimdev/ddutils/render/RGBA.java +++ b/src/main/java/org/dimdev/ddutils/RGBA.java @@ -1,4 +1,4 @@ -package org.dimdev.ddutils.render; +package org.dimdev.ddutils; import lombok.Value; diff --git a/src/main/java/org/dimdev/dimdoors/client/TileEntityEntranceRiftRenderer.java b/src/main/java/org/dimdev/dimdoors/client/TileEntityEntranceRiftRenderer.java index b876d8ab..2a9848b8 100644 --- a/src/main/java/org/dimdev/dimdoors/client/TileEntityEntranceRiftRenderer.java +++ b/src/main/java/org/dimdev/dimdoors/client/TileEntityEntranceRiftRenderer.java @@ -7,7 +7,7 @@ import java.util.Random; import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.shared.tileentities.TileEntityEntranceRift; -import org.dimdev.ddutils.render.RGBA; +import org.dimdev.ddutils.RGBA; import net.minecraft.client.renderer.*; import net.minecraft.client.renderer.vertex.*; import net.minecraft.util.EnumFacing; diff --git a/src/main/java/org/dimdev/dimdoors/client/TileEntityFloatingRiftRenderer.java b/src/main/java/org/dimdev/dimdoors/client/TileEntityFloatingRiftRenderer.java index e2f190ef..b8305c49 100644 --- a/src/main/java/org/dimdev/dimdoors/client/TileEntityFloatingRiftRenderer.java +++ b/src/main/java/org/dimdev/dimdoors/client/TileEntityFloatingRiftRenderer.java @@ -3,6 +3,7 @@ package org.dimdev.dimdoors.client; import com.flowpowered.math.TrigMath; import com.flowpowered.math.vector.Vector3f; import com.flowpowered.math.vector.Vector4f; +import org.dimdev.ddutils.RGBA; import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift; import net.minecraft.client.renderer.BufferBuilder; @@ -149,10 +150,13 @@ public class TileEntityFloatingRiftRenderer extends TileEntitySpecialRenderer 0 && !rift.isAlwaysDelete()) { - TileEntityRift newRift = new TileEntityFloatingRift(); + worldIn.setBlockState(pos, ModBlocks.RIFT.getDefaultState()); + TileEntityFloatingRift newRift = (TileEntityFloatingRift) worldIn.getTileEntity(pos); newRift.copyFrom(rift); newRift.updateAvailableLinks(); - worldIn.setBlockState(rift.getPos(), ModBlocks.RIFT.getDefaultState()); - worldIn.setTileEntity(rift.getPos(), newRift); } else { rift.unregister(); } diff --git a/src/main/java/org/dimdev/dimdoors/shared/items/ItemStabilizedRiftSignature.java b/src/main/java/org/dimdev/dimdoors/shared/items/ItemStabilizedRiftSignature.java index 232fbcaf..af390c02 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/org/dimdev/dimdoors/shared/items/ItemStabilizedRiftSignature.java @@ -54,25 +54,25 @@ public class ItemStabilizedRiftSignature extends Item { // TODO: common supercla } pos = pos.offset(side); - RotatedLocation source = getSource(stack); + RotatedLocation target = getTarget(stack); - if (source != null) { - // Place a rift at the destination point - world.setBlockState(pos, ModBlocks.RIFT.getDefaultState()); - TileEntityRift rift1 = (TileEntityRift) world.getTileEntity(pos); - rift1.setSingleDestination(new GlobalDestination(source.getLocation())); - rift1.setRotation(player.rotationYaw, 0); - rift1.register(); - - // Place a rift at the source point - if (!source.getLocation().getBlockState().getBlock().equals(ModBlocks.RIFT)) { - World sourceWorld = source.getLocation().getWorld(); - sourceWorld.setBlockState(source.getLocation().getPos(), ModBlocks.RIFT.getDefaultState()); - TileEntityRift rift2 = (TileEntityRift) source.getLocation().getTileEntity(); - rift2.setRotation(source.getYaw(), 0); - rift2.register(); + if (target != null) { + // Place a rift at the target point + if (!target.getLocation().getBlockState().getBlock().equals(ModBlocks.RIFT)) { + World targetWorld = target.getLocation().getWorld(); + targetWorld.setBlockState(target.getLocation().getPos(), ModBlocks.RIFT.getDefaultState()); + TileEntityRift rift1 = (TileEntityRift) target.getLocation().getTileEntity(); + rift1.setRotation(target.getYaw(), 0); + rift1.register(); } + // Place a rift at the target point + world.setBlockState(pos, ModBlocks.RIFT.getDefaultState()); + TileEntityRift rift2 = (TileEntityRift) world.getTileEntity(pos); + rift2.setSingleDestination(new GlobalDestination(target.getLocation())); + rift2.setRotation(player.rotationYaw, 0); + rift2.register(); + stack.damageItem(1, player); DimDoors.chat(player, "Rift Created"); @@ -98,7 +98,7 @@ public class ItemStabilizedRiftSignature extends Item { // TODO: common supercla } } - public static RotatedLocation getSource(ItemStack itemStack) { + public static RotatedLocation getTarget(ItemStack itemStack) { if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("destination")) { RotatedLocation transform = new RotatedLocation(); transform.readFromNBT(itemStack.getTagCompound().getCompoundTag("destination")); @@ -111,7 +111,7 @@ public class ItemStabilizedRiftSignature extends Item { // TODO: common supercla @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, World worldIn, List tooltip, ITooltipFlag flagIn) { - RotatedLocation transform = getSource(stack); + RotatedLocation transform = getTarget(stack); if (transform != null) { tooltip.add(I18n.translateToLocalFormatted("info.stabilized_rift_signature.bound", transform.getLocation().getX(), transform.getLocation().getY(), transform.getLocation().getZ(), transform.getLocation().getDim())); } else { diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java index ab0807a7..8de94311 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/RiftRegistry.java @@ -173,6 +173,8 @@ import java.util.*; registryTo.rifts.get(to).sources.add(from); registryTo.markDirty(); } + if (to.getTileEntity() instanceof TileEntityRift) ((TileEntityRift) to.getTileEntity()).updateColor(); + if (from.getTileEntity() instanceof TileEntityRift) ((TileEntityRift) from.getTileEntity()).updateColor(); } public static void removeLink(Location from, Location to) { @@ -182,6 +184,8 @@ import java.util.*; registryTo.rifts.get(to).sources.remove(from); registryFrom.markDirty(); registryTo.markDirty(); + if (to.getTileEntity() instanceof TileEntityRift) ((TileEntityRift) to.getTileEntity()).updateColor(); + if (from.getTileEntity() instanceof TileEntityRift) ((TileEntityRift) from.getTileEntity()).updateColor(); } public static void addAvailableLink(Location rift, AvailableLinkInfo link) { // TODO cache rifts with availableLinks diff --git a/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java b/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java index d866cd1c..a7bcbe09 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java +++ b/src/main/java/org/dimdev/dimdoors/shared/rifts/TileEntityRift.java @@ -2,6 +2,7 @@ package org.dimdev.dimdoors.shared.rifts; import org.dimdev.ddutils.nbt.NBTUtils; import org.dimdev.ddutils.nbt.SavedToNBT; +import org.dimdev.ddutils.RGBA; import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.shared.VirtualLocation; import org.dimdev.dimdoors.shared.pockets.Pocket; @@ -39,6 +40,8 @@ import java.util.*; @SavedToNBT @Getter protected float pitch; @SavedToNBT @Getter protected boolean alwaysDelete; // Delete the rift when an entrances rift is broken even if the state was changed or destinations link there. @SavedToNBT @Getter protected float chaosWeight; + @SavedToNBT @Getter protected boolean forcedColor; + @SavedToNBT @Getter protected RGBA color = null; // TODO: update AnnotatedNBT to be able to save these // TODO: option to convert to door on teleportTo? protected boolean riftStateChanged; // not saved @@ -157,6 +160,12 @@ import java.util.*; markDirty(); } + public void setColor(RGBA color) { + forcedColor = color != null; + this.color = color; + markDirty(); + } + public void markStateChanged() { riftStateChanged = true; markDirty(); @@ -187,6 +196,7 @@ import java.util.*; for (WeightedRiftDestination weightedDest : destinations) { weightedDest.getDestination().register(this); } + updateColor(); } public void unregister() { @@ -229,6 +239,7 @@ import java.util.*; } } destinations.removeIf(weightedRiftDestination -> loc.equals(weightedRiftDestination.getDestination().getReferencedRift(getLocation()))); + markDirty(); } // Teleport logic @@ -282,6 +293,44 @@ import java.util.*; TeleportUtils.teleport(entity, new Location(world, pos), newPitch, newYaw); } + public void updateColor() { // TODO: have the registry call this method too + if (!isRegistered()) { + color = new RGBA(0, 0, 0, 1); + return; + } + if (destinations.size() == 0) { + color = new RGBA(0.7f, 0.7f, 0.7f, 1); + return; + } + boolean safe = true; + for (WeightedRiftDestination weightedDestination : destinations) { + boolean destSafe = false; + RiftDestination destination = weightedDestination.getDestination(); + if (destination instanceof PrivateDestination + || destination instanceof PocketExitDestination + || destination instanceof PrivatePocketExitDestination) destSafe = true; + + if (!destSafe && destination.getReferencedRift(getLocation()) != null) { + RiftRegistry.RiftInfo riftInfo = RiftRegistry.getRiftInfo(destination.getReferencedRift(getLocation())); + destSafe = riftInfo != null + && riftInfo.destinations.size() == 1 + && riftInfo.destinations.iterator().next().equals(getLocation()); + } + safe &= destSafe; + } + if (safe) { + color = new RGBA(0, 1, 0, 1); + } else { + color = new RGBA(1, 0, 0, 1); + } + } + + @Override + public void markDirty() { + if (!forcedColor) updateColor(); + super.markDirty(); + } + // Info protected abstract boolean isFloating(); // TODO: make non-abstract? diff --git a/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java b/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java index 23790a1b..dd98dbee 100644 --- a/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java +++ b/src/main/java/org/dimdev/dimdoors/shared/tileentities/TileEntityEntranceRift.java @@ -4,7 +4,7 @@ import org.dimdev.ddutils.nbt.NBTUtils; import org.dimdev.ddutils.nbt.SavedToNBT; import org.dimdev.dimdoors.shared.rifts.TileEntityRift; import org.dimdev.ddutils.Location; -import org.dimdev.ddutils.render.RGBA; +import org.dimdev.ddutils.RGBA; import org.dimdev.ddutils.TeleportUtils; import lombok.Getter; import net.minecraft.entity.Entity; diff --git a/src/main/resources/assets/dimdoors/textures/other/tesseract.png b/src/main/resources/assets/dimdoors/textures/other/tesseract.png index 7658c5bc..1f36c085 100644 Binary files a/src/main/resources/assets/dimdoors/textures/other/tesseract.png and b/src/main/resources/assets/dimdoors/textures/other/tesseract.png differ