Skip to content

Commit

Permalink
Fixed error when pasteing schematic with entities inside it (#1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jun 23, 2022
1 parent fb2527a commit c310b7b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Expand Up @@ -10,33 +10,37 @@ public class SBlockOffset implements BlockOffset {

public static final SBlockOffset ZERO = new SBlockOffset(0, 0, 0);

private final int offsetX;
private final int offsetY;
private final int offsetZ;
private final double offsetX;
private final double offsetY;
private final double offsetZ;

public static BlockOffset fromOffsets(int offsetX, int offsetY, int offsetZ) {
return offsetX == 0 && offsetY == 0 && offsetZ == 0 ? ZERO : new SBlockOffset(offsetX, offsetY, offsetZ);
}

private SBlockOffset(int offsetX, int offsetY, int offsetZ) {
public static BlockOffset fromOffsets(double offsetX, double offsetY, double offsetZ) {
return offsetX == 0 && offsetY == 0 && offsetZ == 0 ? ZERO : new SBlockOffset(offsetX, offsetY, offsetZ);
}

private SBlockOffset(double offsetX, double offsetY, double offsetZ) {
this.offsetX = offsetX;
this.offsetY = offsetY;
this.offsetZ = offsetZ;
}

@Override
public int getOffsetX() {
return this.offsetX;
return (int) this.offsetX;
}

@Override
public int getOffsetY() {
return this.offsetY;
return (int) this.offsetY;
}

@Override
public int getOffsetZ() {
return this.offsetZ;
return (int) this.offsetZ;
}

@Override
Expand Down
@@ -1,6 +1,7 @@
package com.bgsoftware.superiorskyblock.core;

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.wrappers.BlockOffset;
import com.bgsoftware.superiorskyblock.tag.CompoundTag;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
Expand All @@ -11,20 +12,16 @@ public class SchematicEntity {

private final EntityType entityType;
private final CompoundTag entityTag;
private final Location offset;
private final BlockOffset offset;

public SchematicEntity(EntityType entityType, CompoundTag entityTag, Location offset) {
public SchematicEntity(EntityType entityType, CompoundTag entityTag, BlockOffset offset) {
this.entityType = entityType;
this.entityTag = entityTag;
this.offset = offset;
}

public void spawnEntity(Location min) {
Location entityLocation = offset.clone();
entityLocation.setWorld(min.getWorld());
entityLocation.add(min);

plugin.getNMSTags().spawnEntity(entityType, entityLocation, entityTag);
plugin.getNMSTags().spawnEntity(entityType, offset.applyToLocation(min), entityTag);
}

}
Expand Up @@ -6,17 +6,17 @@
import com.bgsoftware.superiorskyblock.api.wrappers.BlockOffset;
import com.bgsoftware.superiorskyblock.core.ChunkPosition;
import com.bgsoftware.superiorskyblock.core.SBlockOffset;
import com.bgsoftware.superiorskyblock.core.SchematicBlockData;
import com.bgsoftware.superiorskyblock.core.SchematicEntity;
import com.bgsoftware.superiorskyblock.core.debug.PluginDebugger;
import com.bgsoftware.superiorskyblock.core.formatting.Formatters;
import com.bgsoftware.superiorskyblock.core.serialization.Serializers;
import com.bgsoftware.superiorskyblock.core.threads.BukkitExecutor;
import com.bgsoftware.superiorskyblock.tag.CompoundTag;
import com.bgsoftware.superiorskyblock.tag.ListTag;
import com.bgsoftware.superiorskyblock.tag.Tag;
import com.bgsoftware.superiorskyblock.world.schematic.BaseSchematic;
import com.bgsoftware.superiorskyblock.core.SchematicBlockData;
import com.bgsoftware.superiorskyblock.core.SchematicEntity;
import com.bgsoftware.superiorskyblock.world.BlockChangeTask;
import com.bgsoftware.superiorskyblock.world.schematic.BaseSchematic;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
Expand Down Expand Up @@ -84,7 +84,9 @@ public SuperiorSchematic(String name, CompoundTag compoundTag) {
EntityType entityType = EntityType.valueOf(compound.getString("entityType"));
CompoundTag entityTag = compound.getCompound("NBT");
Location offset = Serializers.LOCATION_SERIALIZER.deserialize(compound.getString("offset"));
entities.add(new SchematicEntity(entityType, entityTag, offset));
if (offset != null)
entities.add(new SchematicEntity(entityType, entityTag,
SBlockOffset.fromOffsets(offset.getX(), offset.getY(), offset.getZ())));
}

this.entities = Collections.unmodifiableList(entities);
Expand Down

0 comments on commit c310b7b

Please sign in to comment.