Rift colors

This commit is contained in:
Runemoro 2018-01-02 09:39:18 -05:00
parent be184579e1
commit f5cc44e868
11 changed files with 107 additions and 35 deletions

View file

@ -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\"), "

View file

@ -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"

View file

@ -1,4 +1,4 @@
package org.dimdev.ddutils.render;
package org.dimdev.ddutils;
import lombok.Value;

View file

@ -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;

View file

@ -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<Ti
@Override
public void render(TileEntityFloatingRift te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
double radian = update(partialTicks) * TrigMath.DEG_TO_RAD;
RGBA color = te.getColor();
if (color == null) color = new RGBA(1, 0.5f, 1, 1);
GlStateManager.enableLighting();
GlStateManager.pushMatrix();
GlStateManager.disableCull();
GlStateManager.enableBlend();
bindTexture(tesseract_path);
@ -164,13 +168,15 @@ public class TileEntityFloatingRiftRenderer extends TileEntitySpecialRenderer<Ti
for (int i = 0; i < tesseract.length; i+=4) {
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
project(worldRenderer, rotation(tesseract[i], radian),0,0);
project(worldRenderer, rotation(tesseract[i+1], radian),0,1);
project(worldRenderer, rotation(tesseract[i+2], radian),1,1);
project(worldRenderer, rotation(tesseract[i+3], radian),1,0);
GlStateManager.color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
project(worldRenderer, rotation(tesseract[i], radian),0,0, color);
project(worldRenderer, rotation(tesseract[i+1], radian),0,1, color);
project(worldRenderer, rotation(tesseract[i+2], radian),1,1, color);
project(worldRenderer, rotation(tesseract[i+3], radian),1,0, color);
tessellator.draw();
}
GlStateManager.disableBlend();
GlStateManager.enableCull();
GlStateManager.popMatrix();
GlStateManager.enableLighting();
@ -194,11 +200,11 @@ public class TileEntityFloatingRiftRenderer extends TileEntitySpecialRenderer<Ti
z * TrigMath.sin(angle) + w * TrigMath.cos(angle));
}
private void project(BufferBuilder buffer, Vector4f vector, int u, int v) {
private void project(BufferBuilder buffer, Vector4f vector, int u, int v, RGBA color) {
double scalar = 1d/(vector.getW()+1d);
Vector3f center = Vector3f.from(0.5f);
Vector3f vector1 = vector.toVector3().mul(scalar);
buffer.pos(vector1.getX(), vector1.getY(), vector1.getZ()).tex(u,v).color(1f,1f,1f,1f).endVertex();
buffer.pos(vector1.getX(), vector1.getY(), vector1.getZ()).tex(u,v).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex();
}
}

View file

@ -128,12 +128,12 @@ public abstract class BlockDimensionalDoor extends BlockDoor implements IRiftPro
if (!hasTileEntity(state)) return;
TileEntityEntranceRift rift = getRift(worldIn, pos, state);
super.breakBlock(worldIn, pos, state);
if (worldIn.isRemote) return;
if (rift.isPlaceRiftOnBreak() || rift.isRegistered() && RiftRegistry.getRiftInfo(rift.getLocation()).getSources().size() > 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();
}

View file

@ -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<String> 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 {

View file

@ -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

View file

@ -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?

View file

@ -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;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 15 KiB