Skip to content

Commit

Permalink
update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Ste3et committed Jan 14, 2024
1 parent 2440740 commit f3b202e
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ public HashSet<fEntity> getEntityMap(Location startLocation, BlockFace direction

locationList.add(entity);
String customName = entity.getCustomName();
if (customName.equalsIgnoreCase("#ITEM#")
|| customName.equalsIgnoreCase("#BLOCK#")
|| customName.equalsIgnoreCase("#SITZ#")
|| customName.startsWith("#Light")
|| customName.startsWith("/")
|| customName.toUpperCase().startsWith("#DYE_")) {
entity.setNameVisibility(false);
if(entity.hasCustomName()) {
if (customName.equalsIgnoreCase("#ITEM#")
|| customName.equalsIgnoreCase("#BLOCK#")
|| customName.equalsIgnoreCase("#SITZ#")
|| customName.startsWith("#Light")
|| customName.startsWith("/")
|| customName.toUpperCase().startsWith("#DYE_")) {
entity.setNameVisibility(false);
}
}
});
FurnitureLib.debug("FurnitureLib {ModelHandler} -> Calculate Entities Finish");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public String getString(String key, String defaultValue) {
return defaultValue;
}

return str.replaceAll("\"", "");
return str != null ? str.replaceAll("\"", "") : str;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.Particle.DustOptions;
import org.bukkit.block.Block;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.NumberConversions;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;

import de.Ste3et_C0st.FurnitureLib.main.Type.BodyPart;
import de.Ste3et_C0st.FurnitureLib.main.entity.fArmorStand;
import de.Ste3et_C0st.FurnitureLib.main.entity.fInventory.EquipmentSlot;

import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -602,4 +609,35 @@ public Map<String, Object> serialize() {
result.put("maxZ", this.maxZ);
return result;
}

public void debugParticle(World world) {
final Location startLocation = new Vector(this.minX, this.minY, this.minZ).toLocation(world);
final Location endLocation = new Vector(this.maxX, this.maxY, this.maxZ).toLocation(world);

final List<Vector> locationList = showCuboid(startLocation, endLocation, .25);
final Color color = Color.magenta;
final DustOptions option = new DustOptions(org.bukkit.Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 1f);

locationList.stream().forEach(loc -> {
world.spawnParticle(Particle.REDSTONE, loc.toLocation(world), 1, option);
});
}

private List<Vector> showCuboid(Location aLoc, Location bLoc, double step) {
List<Vector> result = new ArrayList<Vector>();
double[] xArr = {Math.min(aLoc.getX(), bLoc.getX()), Math.max(aLoc.getX(), bLoc.getX())};
double[] yArr = {Math.min(aLoc.getY(), bLoc.getY()), Math.max(aLoc.getY(), bLoc.getY())};
double[] zArr = {Math.min(aLoc.getZ(), bLoc.getZ()), Math.max(aLoc.getZ(), bLoc.getZ())};

for (double x = xArr[0]; x < xArr[1]; x += step) for (double y : yArr) for (double z : zArr) {
result.add(new Vector(x, y, z));
}
for (double y = yArr[0]; y < yArr[1]; y += step) for (double x : xArr) for (double z : zArr) {
result.add(new Vector(x, y, z));
}
for (double z = zArr[0]; z < zArr[1]; z += step) for (double y : yArr) for (double x : xArr) {
result.add(new Vector(x, y, z));
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@
import org.bukkit.util.Vector;
import org.joml.Vector3f;

import de.Ste3et_C0st.FurnitureLib.main.entity.fBlock_display;
import de.Ste3et_C0st.FurnitureLib.main.entity.fDisplay;
import de.Ste3et_C0st.FurnitureLib.main.entity.fEntity;

public class EntitySize {

private final double x, y, z;


private double x, y, z;

public EntitySize(double width, double height) {
this.x = width;
this.z = width;
this.y = height;
this(width, height, width);
}

public EntitySize(double x, double y, double z) {
this.x = x;
this.z = y;
this.y = z;
}

public EntitySize(Vector3f vector3f) {
this.x = vector3f.x;
this.y = vector3f.y;
this.z = vector3f.z;
this(vector3f.x, vector3f.y, vector3f.z);
}

public static EntitySize of(double x, double y, double z) {
return new EntitySize(x, y, z);
}

public static EntitySize of(Vector3f vector3f) {
return new EntitySize(vector3f.x, vector3f.y, vector3f.z);
}

public double getWidth() {
Expand Down Expand Up @@ -48,7 +61,25 @@ public Vector toVector() {
return new Vector((float) this.x,(float) this.y,(float) this.z);
}

public BoundingBox getBoundingBox(Vector vector) {
public BoundingBox getBoundingBox(Vector vector) {
return BoundingBox.of(vector, toVector());
}

public BoundingBox toBoundingBox(fEntity entity) {
return BoundingBox.of(entity.getLocation(), x, y, z);
}

public void write(Vector3f scale) {
this.write(scale.x, scale.y, scale.z);
}

public void write(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}

public String toString() {
return "EntitySize {" + this.x +", " + this.y +", " + this.z +"}";
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import de.Ste3et_C0st.FurnitureLib.Crafting.Project;
import de.Ste3et_C0st.FurnitureLib.SchematicLoader.functions.functionManager;
import de.Ste3et_C0st.FurnitureLib.SchematicLoader.functions.projectFunction;
import de.Ste3et_C0st.FurnitureLib.main.entity.SizeableEntity;
import de.Ste3et_C0st.FurnitureLib.main.entity.fArmorStand;
import de.Ste3et_C0st.FurnitureLib.main.entity.fBlock_display;
import de.Ste3et_C0st.FurnitureLib.main.entity.fContainerEntity;
import de.Ste3et_C0st.FurnitureLib.main.entity.fDisplay;
import de.Ste3et_C0st.FurnitureLib.main.entity.fEntity;
import de.Ste3et_C0st.FurnitureLib.main.entity.fItem_display;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -88,9 +93,14 @@ public boolean runFunction(Player p) {
}

public boolean runOldFunctions(Player p) {
// getObjID().getPacketList().stream().filter(fBlock_display.class::isInstance).map(fBlock_display.class::cast).forEach(entry -> {
// entry.getBoundingBox().debugParticle(getWorld());
// });

ItemStack stack = p.getInventory().getItemInMainHand();
if (stack != null) {
Material m = stack.getType();

if (m.equals(Material.AIR) || !m.isBlock()) {
for (fEntity stand : getfAsList()) {
if (stand.getName().startsWith("#ITEM")) {
Expand All @@ -102,17 +112,22 @@ public boolean runOldFunctions(Player p) {
is.setAmount(1);
getWorld().dropItem(getLocation(), is);
}
if (p.getInventory().getItemInMainHand() != null) {
ItemStack is = p.getInventory().getItemInMainHand().clone();
if (is.getAmount() <= 0) {
is.setAmount(0);
} else {
is.setAmount(1);
}
if (Objects.nonNull(stack)) {
ItemStack is = stack.clone();
is.setAmount(1);
container.setItemInMainHand(is);
stand.update();
consumeItem(p);
}
}else if(stand instanceof fItem_display) {
fItem_display item_display = fItem_display.class.cast(stand);
if (Objects.nonNull(stack)) {
ItemStack is = stack.clone();
is.setAmount(1);
item_display.setItemStack(is);
stand.update();
consumeItem(p);
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -40,7 +41,12 @@ public FurnitureHelper(ObjectID id) {
this.plugin = id.getProjectOBJ().getPlugin();
this.obj = id;
}

public fEntity spawnEntity(Location location, EntityType type) {
return getManager().spawnEntity(type, location, obj);
}

@Deprecated
public fArmorStand spawnArmorStand(Location loc) {
return getManager().createArmorStand(getObjID(), loc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,5 +421,4 @@ public void setFunctionObject(Object obj) {
this.functionObject = Furniture.class.cast(obj);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.Ste3et_C0st.FurnitureLib.main.entity;

import de.Ste3et_C0st.FurnitureLib.Utilitis.BoundingBox;
import de.Ste3et_C0st.FurnitureLib.Utilitis.EntitySize;

public interface SizeableEntity {

public BoundingBox getBoundingBox();
public EntitySize getEntitySize();

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;
import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagList;
import de.Ste3et_C0st.FurnitureLib.Utilitis.BoundingBox;
import de.Ste3et_C0st.FurnitureLib.Utilitis.DefaultKey;
import de.Ste3et_C0st.FurnitureLib.Utilitis.EntitySize;
import de.Ste3et_C0st.FurnitureLib.Utilitis.Relative;
Expand All @@ -23,7 +24,7 @@
import java.util.HashMap;
import java.util.Objects;

public class fArmorStand extends fContainerEntity{
public class fArmorStand extends fContainerEntity implements SizeableEntity{

public static EntityType type = EntityType.ARMOR_STAND;
private int armorstandID;
Expand Down Expand Up @@ -278,5 +279,9 @@ protected Material getDestroyMaterial() {
}
return Material.AIR;
}


@Override
public BoundingBox getBoundingBox() {
return this.entitySize.getOrDefault().toBoundingBox(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import de.Ste3et_C0st.FurnitureLib.NBT.CraftBlockData;
import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;
import de.Ste3et_C0st.FurnitureLib.Utilitis.DefaultKey;
import de.Ste3et_C0st.FurnitureLib.Utilitis.EntitySize;
import de.Ste3et_C0st.FurnitureLib.main.ObjectID;

public class fBlock_display extends fDisplay{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;

import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;
import de.Ste3et_C0st.FurnitureLib.Utilitis.BoundingBox;
import de.Ste3et_C0st.FurnitureLib.Utilitis.DefaultKey;
import de.Ste3et_C0st.FurnitureLib.main.FurnitureLib;
import de.Ste3et_C0st.FurnitureLib.main.ObjectID;
import de.Ste3et_C0st.FurnitureLib.main.Type.ProtocolFieldsDisplay;

public abstract class fDisplay extends fSize{
public abstract class fDisplay extends fSize implements SizeableEntity{

private DefaultKey<Vector3f> translation = new DefaultKey<Vector3f>(new Vector3f()), scale = new DefaultKey<Vector3f>(new Vector3f());
private DefaultKey<Quaternionf> leftRotation = new DefaultKey<Quaternionf>(new Quaternionf()), rightRotation = new DefaultKey<Quaternionf>(new Quaternionf());
Expand Down Expand Up @@ -201,6 +202,8 @@ public fDisplay setInterpolationDuration(int var0) {

private void writeTransformation() {
final Transformation transformation = getTransformation();

this.entitySize.getOrDefault().write(transformation.getScale());
getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 10, Registry.get(Vector3f.class)), transformation.getTranslation());
getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 11, Registry.get(Vector3f.class)), transformation.getScale());
getWatcher().setObject(new WrappedDataWatcherObject(displayField.getVersionIndex() + 12, Registry.get(Quaternionf.class)), transformation.getLeftRotation());
Expand Down Expand Up @@ -265,29 +268,22 @@ protected void writeDisplaySaveData() {

NBTTagCompound transformation = new NBTTagCompound();

if(this.translation.isDefault() == false) {
final NBTTagCompound translation = new NBTTagCompound();
final Vector3f vector = this.translation.getOrDefault();
translation.setFloat("x", vector.x);
translation.setFloat("y", vector.y);
translation.setFloat("z", vector.z);
transformation.set("translation", translation);
}

if(this.scale.isDefault() == false) {
final NBTTagCompound scale = new NBTTagCompound();
final Vector3f vector = this.scale.getOrDefault();
scale.setFloat("x", vector.x);
scale.setFloat("y", vector.y);
scale.setFloat("z", vector.z);
transformation.set("scale", scale);
}
if(this.translation.isDefault() == false) this.writeVector(this.translation.getOrDefault(), transformation, "translation");
if(this.scale.isDefault() == false) this.writeVector(this.scale.getOrDefault(), transformation, "scale");

this.writeRotation(getLeftRotationObj(), transformation, "left_Rotation");
this.writeRotation(getRightRotationObj(), transformation, "right_Rotation");
if(this.leftRotation.isDefault() == false) this.writeRotation(getLeftRotationObj(), transformation, "left_Rotation");
if(this.rightRotation.isDefault() == false) this.writeRotation(getRightRotationObj(), transformation, "right_Rotation");

if(!transformation.isEmpty()) set("transformation", transformation);
if(transformation.isEmpty() == false) set("transformation", transformation);
}

private void writeVector(final Vector3f vector, final NBTTagCompound transformation, final String name) {
final NBTTagCompound rotation = new NBTTagCompound();
rotation.setFloat("x", vector.x);
rotation.setFloat("y", vector.y);
rotation.setFloat("z", vector.z);
transformation.set(name, rotation);
}

private void writeRotation(final Quaternionf quaternionf, final NBTTagCompound transformation, final String name) {
final NBTTagCompound rotation = new NBTTagCompound();
Expand Down Expand Up @@ -368,4 +364,10 @@ protected int widthField() {
protected int heightField() {
return displayField.getVersionIndex() + 20;
}

@Override
public BoundingBox getBoundingBox() {
System.out.println(this.entitySize.getOrDefault().toString());
return this.entitySize.getOrDefault().toBoundingBox(this);
}
}
Loading

0 comments on commit f3b202e

Please sign in to comment.