mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-18 06:40:55 +00:00
add EntitySpawnEvent
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package com.dfsek.terra.api.event.events;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.util.mutable.MutableBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class containing basic {@link Cancellable} implementation.
|
||||||
|
*/
|
||||||
|
public abstract class AbstractCancellable implements Cancellable {
|
||||||
|
private final MutableBoolean cancelled = new MutableBoolean(false);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancelled) {
|
||||||
|
this.cancelled.set(cancelled);
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package com.dfsek.terra.api.event.events.world.generation;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.event.events.PackEvent;
|
||||||
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
|
import com.dfsek.terra.api.platform.entity.Entity;
|
||||||
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedEntity;
|
||||||
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an entity is spawned via {@link BufferedEntity}.
|
||||||
|
*/
|
||||||
|
public class EntitySpawnEvent implements PackEvent {
|
||||||
|
private final ConfigPack pack;
|
||||||
|
private final Entity entity;
|
||||||
|
private final Location location;
|
||||||
|
|
||||||
|
public EntitySpawnEvent(ConfigPack pack, Entity entity, Location location) {
|
||||||
|
this.pack = pack;
|
||||||
|
this.entity = entity;
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigPack getPack() {
|
||||||
|
return pack;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the entity that triggered the event.
|
||||||
|
*
|
||||||
|
* @return The entity.
|
||||||
|
*/
|
||||||
|
public Entity getEntity() {
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the location of the entity.
|
||||||
|
*
|
||||||
|
* @return Location of the entity.
|
||||||
|
*/
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-13
@@ -1,21 +1,20 @@
|
|||||||
package com.dfsek.terra.api.event.events.world.generation;
|
package com.dfsek.terra.api.event.events.world.generation;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.event.events.AbstractCancellable;
|
||||||
import com.dfsek.terra.api.event.events.Cancellable;
|
import com.dfsek.terra.api.event.events.Cancellable;
|
||||||
import com.dfsek.terra.api.event.events.PackEvent;
|
import com.dfsek.terra.api.event.events.PackEvent;
|
||||||
import com.dfsek.terra.api.platform.block.Block;
|
import com.dfsek.terra.api.platform.block.Block;
|
||||||
import com.dfsek.terra.api.platform.block.state.Container;
|
import com.dfsek.terra.api.platform.block.state.Container;
|
||||||
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedLootApplication;
|
import com.dfsek.terra.api.structures.structure.buffer.items.BufferedLootApplication;
|
||||||
import com.dfsek.terra.api.util.mutable.MutableBoolean;
|
|
||||||
import com.dfsek.terra.config.pack.ConfigPack;
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when loot is populated via {@link BufferedLootApplication}.
|
* Called when loot is populated via {@link BufferedLootApplication}.
|
||||||
*/
|
*/
|
||||||
public class LootPopulateEvent implements PackEvent, Cancellable {
|
public class LootPopulateEvent extends AbstractCancellable implements PackEvent, Cancellable {
|
||||||
private final Block block;
|
private final Block block;
|
||||||
private final Container container;
|
private final Container container;
|
||||||
private final ConfigPack pack;
|
private final ConfigPack pack;
|
||||||
private final MutableBoolean cancelled = new MutableBoolean();
|
|
||||||
|
|
||||||
public LootPopulateEvent(Block block, Container container, ConfigPack pack) {
|
public LootPopulateEvent(Block block, Container container, ConfigPack pack) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
@@ -30,6 +29,7 @@ public class LootPopulateEvent implements PackEvent, Cancellable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block containing the tile entity loot is applied to.
|
* Get the block containing the tile entity loot is applied to.
|
||||||
|
*
|
||||||
* @return Block at which loot is applied.
|
* @return Block at which loot is applied.
|
||||||
*/
|
*/
|
||||||
public Block getBlock() {
|
public Block getBlock() {
|
||||||
@@ -38,19 +38,10 @@ public class LootPopulateEvent implements PackEvent, Cancellable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link Container} representing the inventory.
|
* Get the {@link Container} representing the inventory.
|
||||||
|
*
|
||||||
* @return Inventory recieving loot.
|
* @return Inventory recieving loot.
|
||||||
*/
|
*/
|
||||||
public Container getContainer() {
|
public Container getContainer() {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled.set(cancelled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -21,9 +21,11 @@ public class EntityFunction implements Function<Void> {
|
|||||||
private final EntityType data;
|
private final EntityType data;
|
||||||
private final Returnable<Number> x, y, z;
|
private final Returnable<Number> x, y, z;
|
||||||
private final Position position;
|
private final Position position;
|
||||||
|
private final TerraPlugin main;
|
||||||
|
|
||||||
public EntityFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, TerraPlugin main, Position position) throws ParseException {
|
public EntityFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, TerraPlugin main, Position position) throws ParseException {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
this.main = main;
|
||||||
if(!(data instanceof ConstantExpression)) throw new ParseException("Entity data must be constant", data.getPosition());
|
if(!(data instanceof ConstantExpression)) throw new ParseException("Entity data must be constant", data.getPosition());
|
||||||
|
|
||||||
this.data = main.getWorldHandle().getEntity(((ConstantExpression<String>) data).getConstant());
|
this.data = main.getWorldHandle().getEntity(((ConstantExpression<String>) data).getConstant());
|
||||||
@@ -39,7 +41,7 @@ public class EntityFunction implements Function<Void> {
|
|||||||
|
|
||||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||||
|
|
||||||
arguments.getBuffer().addItem(new BufferedEntity(data), new Vector3(xz.getX(), y.apply(implementationArguments, variableMap).doubleValue(), xz.getZ()).toLocation(arguments.getBuffer().getOrigin().getWorld()));
|
arguments.getBuffer().addItem(new BufferedEntity(data, main), new Vector3(xz.getX(), y.apply(implementationArguments, variableMap).doubleValue(), xz.getZ()).toLocation(arguments.getBuffer().getOrigin().getWorld()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -1,18 +1,24 @@
|
|||||||
package com.dfsek.terra.api.structures.structure.buffer.items;
|
package com.dfsek.terra.api.structures.structure.buffer.items;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.TerraPlugin;
|
||||||
|
import com.dfsek.terra.api.event.events.world.generation.EntitySpawnEvent;
|
||||||
import com.dfsek.terra.api.math.vector.Location;
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
|
import com.dfsek.terra.api.platform.entity.Entity;
|
||||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||||
|
|
||||||
public class BufferedEntity implements BufferedItem {
|
public class BufferedEntity implements BufferedItem {
|
||||||
|
|
||||||
private final EntityType type;
|
private final EntityType type;
|
||||||
|
private final TerraPlugin main;
|
||||||
|
|
||||||
public BufferedEntity(EntityType type) {
|
public BufferedEntity(EntityType type, TerraPlugin main) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.main = main;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paste(Location origin) {
|
public void paste(Location origin) {
|
||||||
origin.clone().add(0.5, 0, 0.5).getWorld().spawnEntity(origin, type);
|
Entity entity = origin.clone().add(0.5, 0, 0.5).getWorld().spawnEntity(origin, type);
|
||||||
|
main.getEventManager().callEvent(new EntitySpawnEvent(main.getWorld(entity.getWorld()).getGenerator().getConfigPack(), entity, entity.getLocation()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
public class MutableBoolean implements MutablePrimitive<Boolean> {
|
public class MutableBoolean implements MutablePrimitive<Boolean> {
|
||||||
private boolean value;
|
private boolean value;
|
||||||
|
|
||||||
|
public MutableBoolean() {
|
||||||
|
this.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableBoolean(boolean value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean get() {
|
public Boolean get() {
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
Reference in New Issue
Block a user