Skip to content

Commit

Permalink
fix up painting spawn handling reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 23, 2021
1 parent 77b0ea3 commit 8264a6b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
Expand Up @@ -764,7 +764,7 @@ else if (entity_type.getBukkitEntityType() == EntityType.FALLING_BLOCK) {
// <EntityTag.fallingblock_material>
// -->
for (Mechanism mech : mechanisms) {
if (mech.getName().equalsIgnoreCase("fallingblock_type")) {
if (mech.getName().equals("fallingblock_type")) {
material = mech.valueAsType(MaterialTag.class);
mechanisms.remove(mech);
break;
Expand All @@ -779,6 +779,42 @@ else if (entity_type.getBukkitEntityType() == EntityType.FALLING_BLOCK) {
entity = location.getWorld().spawnFallingBlock(location, material.getModernData());
uuid = entity.getUniqueId();
}
else if (entity_type.getBukkitEntityType() == EntityType.PAINTING) {
entity = entity_type.spawnNewEntity(location, mechanisms, entityScript);
location = location.clone();
Painting painting = (Painting) entity;
Art art = null;
BlockFace face = null;
try {
for (Mechanism mech : mechanisms) {
if (mech.getName().equals("painting")) {
art = Art.valueOf(mech.getValue().asString().toUpperCase());
}
else if (mech.getName().equals("rotation")) {
face = BlockFace.valueOf(mech.getValue().asString().toUpperCase());
}
}
}
catch (Exception ex) {
// ignore
}
if (art != null && face != null) { // Paintings are the worst
if (art.getBlockHeight() % 2 == 0) {
location.subtract(0, 1, 0);
}
if (art.getBlockWidth() % 2 == 0) {
if (face == BlockFace.WEST) {
location.subtract(0, 0, 1);
}
else if (face == BlockFace.SOUTH) {
location.subtract(1, 0, 0);
}
}
painting.teleport(location);
painting.setFacingDirection(face, true);
painting.setArt(art, true);
}
}
else {
entity = entity_type.spawnNewEntity(location, mechanisms, entityScript);
if (entity == null) {
Expand Down Expand Up @@ -2475,17 +2511,7 @@ else if (object.getBukkitEntity() instanceof Hanging) {
// Returns the entity's full description, including all properties.
// -->
registerTag("describe", (attribute, object) -> {
ArrayList<Mechanism> waitingMechs;
if (object.isSpawnedOrValidForTag()) {
waitingMechs = new ArrayList<>();
for (Map.Entry<StringHolder, ObjectTag> property : PropertyParser.getPropertiesMap(object).map.entrySet()) {
waitingMechs.add(new Mechanism(new ElementTag(property.getKey().str), property.getValue()));
}
}
else {
waitingMechs = new ArrayList<>(object.getWaitingMechanisms());
}
return new EntityTag(object.entity_type, waitingMechs);
return object.describe();
});

// <--[tag]
Expand Down Expand Up @@ -2527,6 +2553,20 @@ else if (object.getBukkitEntity() instanceof Hanging) {
});
}

public EntityTag describe() {
ArrayList<Mechanism> waitingMechs;
if (isSpawnedOrValidForTag()) {
waitingMechs = new ArrayList<>();
for (Map.Entry<StringHolder, ObjectTag> property : PropertyParser.getPropertiesMap(this).map.entrySet()) {
waitingMechs.add(new Mechanism(new ElementTag(property.getKey().str), property.getValue()));
}
}
else {
waitingMechs = new ArrayList<>(getWaitingMechanisms());
}
return new EntityTag(entity_type, waitingMechs);
}

public static ObjectTagProcessor<EntityTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerSpawnedOnlyTag(String name, TagRunnable.ObjectInterface<EntityTag> runnable, String... variants) {
Expand All @@ -2551,7 +2591,7 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
return tagProcessor.getObjectAttribute(this, attribute);
}

private ArrayList<Mechanism> mechanisms = new ArrayList<>();
public ArrayList<Mechanism> mechanisms = new ArrayList<>();

public ArrayList<Mechanism> getWaitingMechanisms() {
return mechanisms;
Expand Down
Expand Up @@ -596,7 +596,7 @@ public LocationTag add(Vector input) {

@Override
public LocationTag add(Location input) {
super.add(input);
super.add(input.getX(), input.getY(), input.getZ());
return this;
}

Expand Down
Expand Up @@ -113,7 +113,10 @@ public void adjust(Mechanism mechanism) {
// <server.art_types>
// -->
if (mechanism.matches("painting") && mechanism.requireEnum(false, Art.values())) {
((Painting) painting.getBukkitEntity()).setArt(Art.valueOf(mechanism.getValue().asString().toUpperCase()));
Art art = Art.valueOf(mechanism.getValue().asString().toUpperCase());
if (((Painting) painting.getBukkitEntity()).getArt() != art) {
((Painting) painting.getBukkitEntity()).setArt(art, true);
}
}
}
}
Expand Up @@ -118,7 +118,10 @@ public void adjust(Mechanism mechanism) {
// <EntityTag.rotation_vector>
// -->
if (mechanism.matches("rotation") && mechanism.requireEnum(false, BlockFace.values())) {
setRotation(BlockFace.valueOf(mechanism.getValue().asString().toUpperCase()));
BlockFace face = BlockFace.valueOf(mechanism.getValue().asString().toUpperCase());
if (getRotation() != face) {
setRotation(face);
}
}
}
}

0 comments on commit 8264a6b

Please sign in to comment.