Events are defined statically in normal classes and added handler for extensions to add their built-ins
This commit is contained in:
1 parent
815c75b827
commit
3105d5bb71
11 files changed
+126
-113
No files matched your search
@@ -208,9 +208,10 @@ public class CarpetEventServer
|
||||
}
|
||||
}
|
||||
|
||||
public enum Event
|
||||
public static class Event
|
||||
{
|
||||
TICK("tick", 0, true)
|
||||
public static final Map<String, Event> byName = new HashMap<>();
|
||||
public static final Event TICK = new Event("tick", 0, true)
|
||||
{
|
||||
@Override
|
||||
public void onTick()
|
||||
@@ -220,8 +221,8 @@ public class CarpetEventServer
|
||||
withWorld(CarpetServer.minecraft_server.getWorld(World.OVERWORLD))
|
||||
);
|
||||
}
|
||||
},
|
||||
NETHER_TICK("tick_nether", 0, true)
|
||||
};
|
||||
public static final Event NETHER_TICK = new Event("tick_nether", 0, true)
|
||||
{
|
||||
@Override
|
||||
public void onTick()
|
||||
@@ -231,8 +232,8 @@ public class CarpetEventServer
|
||||
withWorld(CarpetServer.minecraft_server.getWorld(World.NETHER))
|
||||
);
|
||||
}
|
||||
},
|
||||
ENDER_TICK("tick_ender", 0, true)
|
||||
};
|
||||
public static final Event ENDER_TICK = new Event("tick_ender", 0, true)
|
||||
{
|
||||
@Override
|
||||
public void onTick()
|
||||
@@ -242,8 +243,8 @@ public class CarpetEventServer
|
||||
withWorld(CarpetServer.minecraft_server.getWorld(World.END))
|
||||
);
|
||||
}
|
||||
},
|
||||
CHUNK_GENERATED("chunk_generated", 2, true)
|
||||
};
|
||||
public static final Event CHUNK_GENERATED = new Event("chunk_generated", 2, true)
|
||||
{
|
||||
@Override
|
||||
public void onChunkGenerated(ServerWorld world, Chunk chunk)
|
||||
@@ -258,33 +259,33 @@ public class CarpetEventServer
|
||||
}, () -> CarpetServer.minecraft_server.getCommandSource().withWorld(world)
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
PLAYER_JUMPS("player_jumps", 1, false)
|
||||
public static final Event PLAYER_JUMPS = new Event("player_jumps", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_DEPLOYS_ELYTRA("player_deploys_elytra", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_DEPLOYS_ELYTRA = new Event("player_deploys_elytra", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_WAKES_UP("player_wakes_up", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_WAKES_UP = new Event("player_wakes_up", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Arrays.asList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_RIDES("player_rides", 5, false)
|
||||
};
|
||||
public static final Event PLAYER_RIDES = new Event("player_rides", 5, false)
|
||||
{
|
||||
@Override
|
||||
public void onMountControls(ServerPlayerEntity player, float strafeSpeed, float forwardSpeed, boolean jumping, boolean sneaking)
|
||||
@@ -297,8 +298,8 @@ public class CarpetEventServer
|
||||
((c, t) -> new NumericValue(sneaking))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_USES_ITEM("player_uses_item", 3, false)
|
||||
};
|
||||
public static final Event PLAYER_USES_ITEM = new Event("player_uses_item", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
|
||||
@@ -313,8 +314,8 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_CLICKS_BLOCK("player_clicks_block", 3, false)
|
||||
};
|
||||
public static final Event PLAYER_CLICKS_BLOCK = new Event("player_clicks_block", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onBlockAction(ServerPlayerEntity player, BlockPos blockpos, Direction facing)
|
||||
@@ -328,8 +329,8 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_RIGHT_CLICKS_BLOCK("player_right_clicks_block", 6, false)
|
||||
};
|
||||
public static final Event PLAYER_RIGHT_CLICKS_BLOCK = new Event("player_right_clicks_block", 6, false)
|
||||
{
|
||||
@Override
|
||||
public void onBlockHit(ServerPlayerEntity player, Hand enumhand, BlockHitResult hitRes)//ItemStack itemstack, Hand enumhand, BlockPos blockpos, Direction enumfacing, Vec3d vec3d)
|
||||
@@ -354,8 +355,8 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_INTERACTS_WITH_BLOCK("player_interacts_with_block", 5, false)
|
||||
};
|
||||
public static final Event PLAYER_INTERACTS_WITH_BLOCK = new Event("player_interacts_with_block", 5, false)
|
||||
{
|
||||
@Override
|
||||
public void onBlockHit(ServerPlayerEntity player, Hand enumhand, BlockHitResult hitRes)
|
||||
@@ -378,8 +379,8 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_PLACES_BLOCK("player_places_block", 4, false)
|
||||
};
|
||||
public static final Event PLAYER_PLACES_BLOCK = new Event("player_places_block", 4, false)
|
||||
{
|
||||
@Override
|
||||
public void onBlockPlaced(ServerPlayerEntity player, BlockPos pos, Hand enumhand, ItemStack itemstack)
|
||||
@@ -391,8 +392,8 @@ public class CarpetEventServer
|
||||
((c, t) -> new BlockValue(null, player.getServerWorld(), pos))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_BREAK_BLOCK("player_breaks_block", 2, false)
|
||||
};
|
||||
public static final Event PLAYER_BREAK_BLOCK = new Event("player_breaks_block", 2, false)
|
||||
{
|
||||
@Override
|
||||
public void onBlockBroken(ServerPlayerEntity player, BlockPos pos, BlockState previousBS)
|
||||
@@ -402,8 +403,8 @@ public class CarpetEventServer
|
||||
((c, t) -> new BlockValue(previousBS, player.getServerWorld(), pos))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_INTERACTS_WITH_ENTITY("player_interacts_with_entity", 3, false)
|
||||
};
|
||||
public static final Event PLAYER_INTERACTS_WITH_ENTITY = new Event("player_interacts_with_entity", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand)
|
||||
@@ -414,8 +415,8 @@ public class CarpetEventServer
|
||||
((c, t) -> new StringValue(enumhand==Hand.MAIN_HAND?"mainhand":"offhand"))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_ATTACKS_ENTITY("player_attacks_entity", 2, false)
|
||||
};
|
||||
public static final Event PLAYER_ATTACKS_ENTITY = new Event("player_attacks_entity", 2, false)
|
||||
{
|
||||
@Override
|
||||
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand)
|
||||
@@ -425,41 +426,41 @@ public class CarpetEventServer
|
||||
((c, t) -> new EntityValue(entity))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_STARTS_SNEAKING("player_starts_sneaking", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_STARTS_SNEAKING = new Event("player_starts_sneaking", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_STOPS_SNEAKING("player_stops_sneaking", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_STOPS_SNEAKING = new Event("player_stops_sneaking", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_STARTS_SPRINTING("player_starts_sprinting", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_STARTS_SPRINTING = new Event("player_starts_sprinting", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_STOPS_SPRINTING("player_stops_sprinting", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_STOPS_SPRINTING = new Event("player_stops_sprinting", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
PLAYER_RELEASED_ITEM("player_releases_item", 3, false)
|
||||
public static final Event PLAYER_RELEASED_ITEM = new Event("player_releases_item", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
|
||||
@@ -474,8 +475,8 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_FINISHED_USING_ITEM("player_finishes_using_item", 3, false)
|
||||
};
|
||||
public static final Event PLAYER_FINISHED_USING_ITEM = new Event("player_finishes_using_item", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onItemAction(ServerPlayerEntity player, Hand enumhand, ItemStack itemstack)
|
||||
@@ -490,24 +491,24 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_DROPS_ITEM("player_drops_item", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_DROPS_ITEM = new Event("player_drops_item", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_DROPS_STACK("player_drops_stack", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_DROPS_STACK = new Event("player_drops_stack", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_CHOOSES_RECIPE("player_chooses_recipe", 3, false)
|
||||
};
|
||||
public static final Event PLAYER_CHOOSES_RECIPE = new Event("player_chooses_recipe", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onRecipeSelected(ServerPlayerEntity player, Identifier recipe, boolean fullStack)
|
||||
@@ -521,8 +522,8 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_SWITCHES_SLOT("player_switches_slot", 3, false)
|
||||
};
|
||||
public static final Event PLAYER_SWITCHES_SLOT = new Event("player_switches_slot", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onSlotSwitch(ServerPlayerEntity player, int from, int to)
|
||||
@@ -537,16 +538,16 @@ public class CarpetEventServer
|
||||
);
|
||||
}, player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_SWAPS_HANDS("player_swaps_hands", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_SWAPS_HANDS = new Event("player_swaps_hands", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_TAKES_DAMAGE("player_takes_damage", 4, false)
|
||||
};
|
||||
public static final Event PLAYER_TAKES_DAMAGE = new Event("player_takes_damage", 4, false)
|
||||
{
|
||||
@Override
|
||||
public void onDamage(Entity target, float amount, DamageSource source)
|
||||
@@ -561,8 +562,8 @@ public class CarpetEventServer
|
||||
);
|
||||
}, target::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_DEALS_DAMAGE("player_deals_damage", 3, false)
|
||||
};
|
||||
public static final Event PLAYER_DEALS_DAMAGE = new Event("player_deals_damage", 3, false)
|
||||
{
|
||||
@Override
|
||||
public void onDamage(Entity target, float amount, DamageSource source)
|
||||
@@ -576,24 +577,24 @@ public class CarpetEventServer
|
||||
);
|
||||
}, () -> source.getAttacker().getCommandSource());
|
||||
}
|
||||
},
|
||||
PLAYER_DIES("player_dies", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_DIES = new Event("player_dies", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_RESPAWNS("player_respawns", 1, false)
|
||||
};
|
||||
public static final Event PLAYER_RESPAWNS = new Event("player_respawns", 1, false)
|
||||
{
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_CHANGES_DIMENSION("player_changes_dimension", 5, false)
|
||||
};
|
||||
public static final Event PLAYER_CHANGES_DIMENSION = new Event("player_changes_dimension", 5, false)
|
||||
{
|
||||
@Override
|
||||
public void onDimensionChange(ServerPlayerEntity player, Vec3d from, Vec3d to, RegistryKey<World> fromDim, RegistryKey<World> dimTo)
|
||||
@@ -612,15 +613,15 @@ public class CarpetEventServer
|
||||
((c, t) -> toDimStr)
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_CONNECTS("player_connects", 1, false) {
|
||||
};
|
||||
public static final Event PLAYER_CONNECTS = new Event("player_connects", 1, false) {
|
||||
@Override
|
||||
public void onPlayerEvent(ServerPlayerEntity player)
|
||||
{
|
||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
PLAYER_DISCONNECTS("player_disconnects", 2, false) {
|
||||
};
|
||||
public static final Event PLAYER_DISCONNECTS = new Event("player_disconnects", 2, false) {
|
||||
@Override
|
||||
public void onPlayerMessage(ServerPlayerEntity player, String message)
|
||||
{
|
||||
@@ -629,8 +630,8 @@ public class CarpetEventServer
|
||||
((c, t) -> new StringValue(message))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
STATISTICS("statistic", 4, false)
|
||||
};
|
||||
public static final Event STATISTICS = new Event("statistic", 4, false)
|
||||
{
|
||||
private <T> Identifier getStatId(Stat<T> stat)
|
||||
{
|
||||
@@ -653,8 +654,8 @@ public class CarpetEventServer
|
||||
((c, t) -> new NumericValue(amount))
|
||||
), player::getCommandSource);
|
||||
}
|
||||
},
|
||||
LIGHTNING("lightning", 2, true)
|
||||
};
|
||||
public static final Event LIGHTNING = new Event("lightning", 2, true)
|
||||
{
|
||||
@Override
|
||||
public void onWorldEventFlag(ServerWorld world, BlockPos pos, int flag)
|
||||
@@ -666,18 +667,12 @@ public class CarpetEventServer
|
||||
), () -> CarpetServer.minecraft_server.getCommandSource().withWorld(world)
|
||||
);
|
||||
}
|
||||
},
|
||||
;
|
||||
};
|
||||
|
||||
// on projectile thrown (arrow from bows, crossbows, tridents, snoballs, e-pearls
|
||||
|
||||
public final String name;
|
||||
public static final Map<String, Event> byName = new HashMap<String, Event>(){{
|
||||
for (Event e: Event.values())
|
||||
{
|
||||
put(e.name, e);
|
||||
}
|
||||
}};
|
||||
|
||||
public final CallbackList handler;
|
||||
public final boolean globalOnly;
|
||||
Event(String name, int reqArgs, boolean isGlobalOnly)
|
||||
@@ -685,6 +680,7 @@ public class CarpetEventServer
|
||||
this.name = name;
|
||||
this.handler = new CallbackList(reqArgs);
|
||||
this.globalOnly = isGlobalOnly;
|
||||
byName.put(name, this);
|
||||
}
|
||||
public boolean isNeeded()
|
||||
{
|
||||
@@ -717,7 +713,7 @@ public class CarpetEventServer
|
||||
public CarpetEventServer(MinecraftServer server)
|
||||
{
|
||||
this.server = server;
|
||||
for (Event e: Event.values())
|
||||
for (Event e: Event.byName.values())
|
||||
e.handler.callList.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -177,14 +177,16 @@ public class CarpetExpression
|
||||
private final ServerCommandSource source;
|
||||
private final BlockPos origin;
|
||||
private final Expression expr;
|
||||
// these are for extensions
|
||||
public Expression getExpr() {return expr;}
|
||||
public ServerCommandSource getSource() {return source;}
|
||||
public BlockPos getOrigin() {return origin;}
|
||||
|
||||
private static long tickStart = 0L;
|
||||
// dummy entity for dummy requirements in the loot tables (see snowball)
|
||||
private static FallingBlockEntity DUMMY_ENTITY = new FallingBlockEntity(EntityType.FALLING_BLOCK, null);
|
||||
public static final String MARKER_STRING = "__scarpet_marker";
|
||||
|
||||
private static boolean stopAll = false;
|
||||
|
||||
private static final Map<String, Direction> DIRECTION_MAP = Arrays.stream(Direction.values()).collect(Collectors.toMap(Direction::getName, (direction) -> direction));
|
||||
|
||||
private LazyValue booleanStateTest(
|
||||
@@ -3640,7 +3642,6 @@ public class CarpetExpression
|
||||
this.expr = new Expression(expression);
|
||||
this.expr.asAModule(module);
|
||||
|
||||
|
||||
API_BlockManipulation();
|
||||
API_EntityManipulation();
|
||||
API_InventoryManipulation();
|
||||
@@ -3649,6 +3650,7 @@ public class CarpetExpression
|
||||
API_Scoreboard();
|
||||
API_Interapperability();
|
||||
API_GaemMonitoring();
|
||||
CarpetServer.extensions.forEach(e -> e.scarpetApi(this));
|
||||
}
|
||||
|
||||
public boolean fillAndScanCommand(ScriptHost host, int x, int y, int z)
|
||||
|
||||
@@ -12,24 +12,22 @@ import net.minecraft.entity.damage.DamageSource;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EntityEventsGroup
|
||||
{
|
||||
private final Map<EntityEventType, Map<String, CarpetEventServer.ScheduledCall>> actions;
|
||||
private Entity entity;
|
||||
private final Map<Event, Map<String, CarpetEventServer.ScheduledCall>> actions;
|
||||
private final Entity entity;
|
||||
public EntityEventsGroup(Entity e)
|
||||
{
|
||||
actions = new EnumMap<>(EntityEventType.class);
|
||||
actions = new HashMap<>();
|
||||
entity = e;
|
||||
}
|
||||
|
||||
public void onEvent(EntityEventType type, Object... args)
|
||||
public void onEvent(Event type, Object... args)
|
||||
{
|
||||
if (actions.isEmpty()) return; // most of the cases, trying to be nice
|
||||
Map<String, CarpetEventServer.ScheduledCall> actionSet = actions.get(type);
|
||||
@@ -49,7 +47,7 @@ public class EntityEventsGroup
|
||||
if (actionSet.isEmpty()) actions.remove(type);
|
||||
}
|
||||
|
||||
public void addEvent(EntityEventType type, CarpetContext cc, FunctionValue fun, List<Value> extraargs)
|
||||
public void addEvent(Event type, CarpetContext cc, FunctionValue fun, List<Value> extraargs)
|
||||
{
|
||||
if (fun != null)
|
||||
{
|
||||
@@ -67,9 +65,10 @@ public class EntityEventsGroup
|
||||
}
|
||||
|
||||
|
||||
public enum EntityEventType
|
||||
public static class Event
|
||||
{
|
||||
ON_DEATH("on_death", 1)
|
||||
public static final Map<String, Event> byName = new HashMap<>();
|
||||
public static final Event ON_DEATH = new Event("on_death", 1)
|
||||
{
|
||||
@Override
|
||||
public List<Value> makeArgs(Entity entity, Object... providedArgs)
|
||||
@@ -79,10 +78,10 @@ public class EntityEventsGroup
|
||||
new StringValue((String)providedArgs[0])
|
||||
);
|
||||
}
|
||||
},
|
||||
ON_REMOVED("on_removed", 0),
|
||||
ON_TICK("on_tick", 0),
|
||||
ON_DAMAGE("on_damaged", 3)
|
||||
};
|
||||
public static final Event ON_REMOVED = new Event("on_removed", 0);
|
||||
public static final Event ON_TICK = new Event("on_tick", 0);
|
||||
public static final Event ON_DAMAGE = new Event("on_damaged", 3)
|
||||
{
|
||||
@Override
|
||||
public List<Value> makeArgs(Entity entity, Object... providedArgs)
|
||||
@@ -98,14 +97,13 @@ public class EntityEventsGroup
|
||||
}
|
||||
};
|
||||
|
||||
public static final Map<String, EntityEventType> byName = Arrays.stream(EntityEventType.values()).collect(Collectors.toMap(ev -> ev.id, ev -> ev));
|
||||
|
||||
public final int argcount;
|
||||
public final String id;
|
||||
EntityEventType(String identifier, int args)
|
||||
Event(String identifier, int args)
|
||||
{
|
||||
id = identifier;
|
||||
argcount = args+1; // entity is not extra
|
||||
byName.put(identifier, this);
|
||||
}
|
||||
public CarpetEventServer.ScheduledCall create(CarpetContext cc, FunctionValue function, List<Value> extraArgs)
|
||||
{
|
||||
|
||||
@@ -1154,7 +1154,7 @@ public class EntityValue extends Value
|
||||
|
||||
public void setEvent(CarpetContext cc, String eventName, FunctionValue fun, List<Value> args)
|
||||
{
|
||||
EntityEventsGroup.EntityEventType event = EntityEventsGroup.EntityEventType.byName.get(eventName);
|
||||
EntityEventsGroup.Event event = EntityEventsGroup.Event.byName.get(eventName);
|
||||
if (event == null)
|
||||
throw new InternalExpressionException("Unknown entity event: " + eventName);
|
||||
((EntityInterface)entity).getEventContainer().addEvent(event, cc, fun, args);
|
||||
|
||||
Reference in new issue
Block a user