From f5cc44e868e57f9be5d3799916c08305d1807812 Mon Sep 17 00:00:00 2001 From: Runemoro Date: Tue, 2 Jan 2018 09:39:18 -0500 Subject: [PATCH] Rift colors --- .../ddutils/nbt/SavedToNBTProcessor.java | 21 ++++++-- build.gradle | 2 +- .../org/dimdev/ddutils/{render => }/RGBA.java | 2 +- .../TileEntityEntranceRiftRenderer.java | 2 +- .../TileEntityFloatingRiftRenderer.java | 18 ++++--- .../shared/blocks/BlockDimensionalDoor.java | 6 +-- .../items/ItemStabilizedRiftSignature.java | 36 ++++++------- .../dimdoors/shared/rifts/RiftRegistry.java | 4 ++ .../dimdoors/shared/rifts/TileEntityRift.java | 49 ++++++++++++++++++ .../tileentities/TileEntityEntranceRift.java | 2 +- .../dimdoors/textures/other/tesseract.png | Bin 198 -> 15005 bytes 11 files changed, 107 insertions(+), 35 deletions(-) rename src/main/java/org/dimdev/ddutils/{render => }/RGBA.java (76%) 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 7658c5bcbc4251eb5f447bacaa0b7dbf4586b648..1f36c085be435b33732bc49823e4d618686a7c25 100644 GIT binary patch literal 15005 zcmeI3&x<2P6vt~32F=dEq6b9;o2)Jh+vy+q*-esROlF+{GY&J6ojEy`?#iT@q`U3z zOfmzqqI>bU;z4Bp08idLh{7VGe}i~XJa|w94|@`XSlyi;JugWy>WY^NB;BuGeP4Bd z>b;k~^!vLzudbz@O(BHVwzukg^mr}&KE6VKpMN;Q^zekcb?75>^{McC1$}(~8HBVS ztmZ**(0ENZoL&Z-PK#uQJ(tc#sJuROv2j8Ip+$}@yORF>iw9}JGArrZ`G(wZYouds zoqJ^ee5YxgpBS2%UazLgL!AcbkpK(BUf1^ZVI>{K)#-USETx5LN^nw1Z-fg92aR2! z=6FQNX9}XBWJ^L(%P4uRq~>l4s;m?wS(B8UC@Z?G>9Qh>Kj~_Uo|Qebt?$)ujhCZV zCEW=ESC^#0V2~MPGmdvGDVnB9vMQ;nNN0%tnH}JvX#3aWAd@(C;v1gj29{$BVO-pD z`ava~4i}n!#`o28rwiHsm>s1k4Y4aJ8ChB+GL5Om?R(wm(o91lUD6|V;8UHlQ0I1> z!0|iIk|n3^r3=$NX*8y5FTCDfZ{gB@uz5-mjFB!>`pq+!NPEP0`kp~HPwA~(Uv&3@ z)t+t6g-D@i>9v!gwL}(rVp)_5@eY;gz3MfO;K1>kj?=BiS++YtDAa0URuzSpZd1#3<2h7GbD`^w(GRO-9NMIzOL>gVoLUfZzAcM+HP;q3wIqu~B{{8FD9T1LKM9?X z&xL;7vuLNo-Nc;m>i_N%3&PATwPpDXA zL42nj46sKwj%iL@rq<)A7iBPfSqi&<*ZL1O!pEooZW}IFNB>|Omi46nZyRP=Y;>@F zOw6h@N#M!A<#sOK&x@5cX$bR`SPuV=bXvtUqi|F`N?Dp4o2?wrKM1R_+mGfKRhfPy zCHx&rlWr(IWJ{B7D4i+au&tn~j#mT2303%?88`HO`gljGg?v6snqT%W(l9Y?I?+^8sFt z3jkr892c7p@N!%L2;1bi*nEJO;{rg~Cdb9*1H2p;0KzsoE;b+F<+uP4w#jj^`2a7+ z1%R+kj*HC)csVWrgl%$MY(ButaRDG~ljCCZ0bY&^0AZUP7n=|8a$Eoi+vK>|e1MnZ z0zlX%$HnFYyc`z*!ZtZBHXq>SxBw8g$#Jpy058V{fUr%Di_HgkIW7Q%Z8CACW-o0L zo4%2*Z=+`5J^p6mF+WFwkZ*I}K z+ID@TIsCr$=V&y#vywtrKWx9SKe}^cCH2)OSHAucefwbbxx1@JcW?ZB@BWkc^LxMD eT%)Sd=rQ!!cdNqN8@WSjqV3I{`lqiPz55r_w=i!2 delta 150 zcmbPRdW>;`3O`$tx4R3&e-K=-clqRrisCg4>?NMQuIvvP`Ng^Qf?BL5FfcI4W`;zR zIOpf)rskCZxeN@>MX8A;sVNHOnI#zt?w-B@DSD~wKyfWk7sn8b)5$46KL598c5M)1 x{`cqq`6CXB5~c|(5+9!1AJ6bo;gQfhdyb)Vhw!iBI(Z?Gah|SzF6*2UngGW#GZ_E?