added inhabited_time and player events revolving around damage, death and respawns.
This commit is contained in:
1 parent
0133ceb507
commit
d6d6b69fcb
12 files changed
+153
-3
No files matched your search
+10
-1
@@ -276,7 +276,8 @@ global_foo = floor(rand(10));
|
|||||||
check_foo_not_zero();
|
check_foo_not_zero();
|
||||||
...
|
...
|
||||||
check_foo_not_zero() -> if(global_foo == 0, global_foo = 1)
|
check_foo_not_zero() -> if(global_foo == 0, global_foo = 1)
|
||||||
</pre># Variables and Constants
|
</pre>
|
||||||
|
# Variables and Constants
|
||||||
|
|
||||||
`scarpet` provides a number of constants that can be used literally in scripts
|
`scarpet` provides a number of constants that can be used literally in scripts
|
||||||
|
|
||||||
@@ -2055,6 +2056,10 @@ Returns generation status as per the ticket system. Can return any value from se
|
|||||||
can only be stable in a few states: `full`, `features`, `liquid_carvers`, and `structure_starts`. Returns `null`
|
can only be stable in a few states: `full`, `features`, `liquid_carvers`, and `structure_starts`. Returns `null`
|
||||||
if the chunk is not in memory unless called with optional `true`.
|
if the chunk is not in memory unless called with optional `true`.
|
||||||
|
|
||||||
|
### `inhabited_time(pos)`
|
||||||
|
|
||||||
|
Returns inhabited time for a chunk.
|
||||||
|
|
||||||
### `structures(pos), structures(pos, structure_name)`
|
### `structures(pos), structures(pos, structure_name)`
|
||||||
|
|
||||||
Returns structure information for a given block position. Note that structure information is the same for all the
|
Returns structure information for a given block position. Note that structure information is the same for all the
|
||||||
@@ -2872,6 +2877,10 @@ __on_player_interacts_with_block(player, hand, block, face, hitvec) //right cli
|
|||||||
__on_player_places_block(player, item_tuple, hand, block) // player have just placed the block.
|
__on_player_places_block(player, item_tuple, hand, block) // player have just placed the block.
|
||||||
__on_player_interacts_with_entity(player, entity, hand)
|
__on_player_interacts_with_entity(player, entity, hand)
|
||||||
__on_player_attacks_entity(player, entity)
|
__on_player_attacks_entity(player, entity)
|
||||||
|
__on_player_takes_damage(player, amount, source, source_entity)
|
||||||
|
__on_player_deals_damage(player, amount, entity)
|
||||||
|
__on_player_dies(player)
|
||||||
|
__on_player_respawns(player)
|
||||||
__on_player_rides(player, forward, strafe, jumping, sneaking)
|
__on_player_rides(player, forward, strafe, jumping, sneaking)
|
||||||
__on_player_jumps(player)
|
__on_player_jumps(player)
|
||||||
__on_player_deploys_elytra(player)
|
__on_player_deploys_elytra(player)
|
||||||
|
|||||||
@@ -519,6 +519,10 @@ Returns generation status as per the ticket system. Can return any value from se
|
|||||||
can only be stable in a few states: `full`, `features`, `liquid_carvers`, and `structure_starts`. Returns `null`
|
can only be stable in a few states: `full`, `features`, `liquid_carvers`, and `structure_starts`. Returns `null`
|
||||||
if the chunk is not in memory unless called with optional `true`.
|
if the chunk is not in memory unless called with optional `true`.
|
||||||
|
|
||||||
|
### `inhabited_time(pos)`
|
||||||
|
|
||||||
|
Returns inhabited time for a chunk.
|
||||||
|
|
||||||
### `structures(pos), structures(pos, structure_name)`
|
### `structures(pos), structures(pos, structure_name)`
|
||||||
|
|
||||||
Returns structure information for a given block position. Note that structure information is the same for all the
|
Returns structure information for a given block position. Note that structure information is the same for all the
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ __on_player_interacts_with_block(player, hand, block, face, hitvec) //right cli
|
|||||||
__on_player_places_block(player, item_tuple, hand, block) // player have just placed the block.
|
__on_player_places_block(player, item_tuple, hand, block) // player have just placed the block.
|
||||||
__on_player_interacts_with_entity(player, entity, hand)
|
__on_player_interacts_with_entity(player, entity, hand)
|
||||||
__on_player_attacks_entity(player, entity)
|
__on_player_attacks_entity(player, entity)
|
||||||
|
__on_player_takes_damage(player, amount, source, source_entity)
|
||||||
|
__on_player_deals_damage(player, amount, entity)
|
||||||
|
__on_player_dies(player)
|
||||||
|
__on_player_respawns(player)
|
||||||
__on_player_rides(player, forward, strafe, jumping, sneaking)
|
__on_player_rides(player, forward, strafe, jumping, sneaking)
|
||||||
__on_player_jumps(player)
|
__on_player_jumps(player)
|
||||||
__on_player_deploys_elytra(player)
|
__on_player_deploys_elytra(player)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ hardness
|
|||||||
harvest
|
harvest
|
||||||
in_dimension
|
in_dimension
|
||||||
in_slime_chunk
|
in_slime_chunk
|
||||||
|
inhabited_time
|
||||||
inventory_find
|
inventory_find
|
||||||
inventory_get
|
inventory_get
|
||||||
inventory_remove
|
inventory_remove
|
||||||
|
|||||||
@@ -26,3 +26,7 @@ __on_statistic
|
|||||||
__on_tick
|
__on_tick
|
||||||
__on_tick_ender
|
__on_tick_ender
|
||||||
__on_tick_nether
|
__on_tick_nether
|
||||||
|
__on_player_takes_damage
|
||||||
|
__on_player_deals_damage
|
||||||
|
__on_player_dies
|
||||||
|
__on_player_respawns
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
hardness blast_resistance top loaded suffocates power ticks_randomly update block_tick random_tick in_slime_chunk
|
hardness blast_resistance top loaded suffocates power ticks_randomly update block_tick random_tick in_slime_chunk
|
||||||
set without_updates
|
set without_updates
|
||||||
blocks_movement block_sound material map_colour property block_properties block_data poi set_poi
|
blocks_movement block_sound material map_colour property block_properties block_data poi set_poi
|
||||||
place_item set_biome biome loaded_status generation_status chunk_tickets
|
place_item set_biome biome loaded_status generation_status inhabited_time chunk_tickets
|
||||||
structures structure_references set_structure reset_chunk
|
structures structure_references set_structure reset_chunk
|
||||||
|
|
||||||
scoreboard scoreboard_add scoreboard_remove scoreboard_display
|
scoreboard scoreboard_add scoreboard_remove scoreboard_display
|
||||||
@@ -104,6 +104,10 @@
|
|||||||
__on_tick
|
__on_tick
|
||||||
__on_tick_ender
|
__on_tick_ender
|
||||||
__on_tick_nether
|
__on_tick_nether
|
||||||
|
__on_player_takes_damage
|
||||||
|
__on_player_deals_damage
|
||||||
|
__on_player_dies
|
||||||
|
__on_player_respawns
|
||||||
</Keywords>
|
</Keywords>
|
||||||
<Keywords name="Keywords8">$</Keywords>
|
<Keywords name="Keywords8">$</Keywords>
|
||||||
<Keywords name="Delimiters">00' 01\ 02' 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
|
<Keywords name="Delimiters">00' 01\ 02' 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import carpet.script.EntityEventsGroup;
|
|||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
import net.minecraft.entity.damage.DamageTracker;
|
import net.minecraft.entity.damage.DamageTracker;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@@ -12,8 +13,11 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import static carpet.script.CarpetEventServer.Event.PLAYER_DEALS_DAMAGE;
|
||||||
|
import static carpet.script.CarpetEventServer.Event.PLAYER_TAKES_DAMAGE;
|
||||||
|
|
||||||
@Mixin(DamageTracker.class)
|
@Mixin(DamageTracker.class)
|
||||||
public class DamageTracker_scarpetEventMixin
|
public abstract class DamageTracker_scarpetEventMixin
|
||||||
{
|
{
|
||||||
@Shadow @Final private LivingEntity entity;
|
@Shadow @Final private LivingEntity entity;
|
||||||
|
|
||||||
@@ -21,5 +25,13 @@ public class DamageTracker_scarpetEventMixin
|
|||||||
private void onDamageTaken(DamageSource damageSource_1, float float_1, float float_2, CallbackInfo ci)
|
private void onDamageTaken(DamageSource damageSource_1, float float_1, float float_2, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
((EntityInterface)entity).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DAMAGE, entity, float_2, damageSource_1);
|
((EntityInterface)entity).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DAMAGE, entity, float_2, damageSource_1);
|
||||||
|
if (entity instanceof ServerPlayerEntity && PLAYER_TAKES_DAMAGE.isNeeded())
|
||||||
|
{
|
||||||
|
PLAYER_TAKES_DAMAGE.onDamage(entity, float_2, damageSource_1);
|
||||||
|
}
|
||||||
|
if (damageSource_1.getAttacker() instanceof ServerPlayerEntity && PLAYER_DEALS_DAMAGE.isNeeded())
|
||||||
|
{
|
||||||
|
PLAYER_DEALS_DAMAGE.onDamage(entity, float_2, damageSource_1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package carpet.mixins;
|
||||||
|
|
||||||
|
import net.minecraft.server.PlayerManager;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import static carpet.script.CarpetEventServer.Event.PLAYER_RESPAWNS;
|
||||||
|
|
||||||
|
@Mixin(PlayerManager.class)
|
||||||
|
public class PlayerManager_scarpetEventsMixin
|
||||||
|
{
|
||||||
|
@Inject(method = "respawnPlayer", at = @At("HEAD"))
|
||||||
|
private void onRespawn(ServerPlayerEntity player, DimensionType dimension, boolean alive, CallbackInfoReturnable<ServerPlayerEntity> cir)
|
||||||
|
{
|
||||||
|
PLAYER_RESPAWNS.onPlayerEvent(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import static carpet.script.CarpetEventServer.Event.PLAYER_DIES;
|
||||||
import static carpet.script.CarpetEventServer.Event.PLAYER_FINISHED_USING_ITEM;
|
import static carpet.script.CarpetEventServer.Event.PLAYER_FINISHED_USING_ITEM;
|
||||||
import static carpet.script.CarpetEventServer.Event.STATISTICS;
|
import static carpet.script.CarpetEventServer.Event.STATISTICS;
|
||||||
|
|
||||||
@@ -61,6 +62,10 @@ public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
|
|||||||
private void onDeathEvent(DamageSource source, CallbackInfo ci)
|
private void onDeathEvent(DamageSource source, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, source.name);
|
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, source.name);
|
||||||
|
if (PLAYER_DIES.isNeeded())
|
||||||
|
{
|
||||||
|
PLAYER_DIES.onPlayerEvent((ServerPlayerEntity) (Object)this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(method = "method_14218", at = @At(
|
@Redirect(method = "method_14218", at = @At(
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import carpet.script.value.StringValue;
|
|||||||
import carpet.script.value.Value;
|
import carpet.script.value.Value;
|
||||||
import carpet.utils.Messenger;
|
import carpet.utils.Messenger;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
@@ -479,6 +480,53 @@ public class CarpetEventServer
|
|||||||
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
PLAYER_TAKES_DAMAGE("player_takes_damage", 4, false)
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onDamage(Entity target, float amount, DamageSource source)
|
||||||
|
{
|
||||||
|
handler.call( () ->
|
||||||
|
{
|
||||||
|
return Arrays.asList(
|
||||||
|
((c, t) -> new EntityValue(target)),
|
||||||
|
((c, t) -> new NumericValue(amount)),
|
||||||
|
((c, t) ->new StringValue(source.getName())),
|
||||||
|
((c, t) -> source.getAttacker()==null?Value.NULL:new EntityValue(source.getAttacker()))
|
||||||
|
);
|
||||||
|
}, target::getCommandSource);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PLAYER_DEALS_DAMAGE("player_deals_damage", 3, false)
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onDamage(Entity target, float amount, DamageSource source)
|
||||||
|
{
|
||||||
|
handler.call( () ->
|
||||||
|
{
|
||||||
|
return Arrays.asList(
|
||||||
|
((c, t) -> new EntityValue(source.getAttacker())),
|
||||||
|
((c, t) -> new NumericValue(amount)),
|
||||||
|
((c, t) -> new EntityValue(target))
|
||||||
|
);
|
||||||
|
}, () -> source.getAttacker().getCommandSource());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PLAYER_DIES("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)
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onPlayerEvent(ServerPlayerEntity player)
|
||||||
|
{
|
||||||
|
handler.call( () -> Collections.singletonList(((c, t) -> new EntityValue(player))), player::getCommandSource);
|
||||||
|
}
|
||||||
|
},
|
||||||
STATISTICS("statistic", 4, false)
|
STATISTICS("statistic", 4, false)
|
||||||
{
|
{
|
||||||
private <T> Identifier getStatId(Stat<T> stat)
|
private <T> Identifier getStatId(Stat<T> stat)
|
||||||
@@ -551,6 +599,8 @@ public class CarpetEventServer
|
|||||||
public void onBlockBroken(ServerPlayerEntity player, BlockPos pos, BlockState previousBS) { }
|
public void onBlockBroken(ServerPlayerEntity player, BlockPos pos, BlockState previousBS) { }
|
||||||
public void onBlockPlaced(ServerPlayerEntity player, BlockPos pos, Hand enumhand, ItemStack itemstack) { }
|
public void onBlockPlaced(ServerPlayerEntity player, BlockPos pos, Hand enumhand, ItemStack itemstack) { }
|
||||||
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand) { }
|
public void onEntityAction(ServerPlayerEntity player, Entity entity, Hand enumhand) { }
|
||||||
|
public void onDamage(Entity target, float amount, DamageSource source) { }
|
||||||
|
|
||||||
public void onWorldEvent(ServerWorld world, BlockPos pos) { }
|
public void onWorldEvent(ServerWorld world, BlockPos pos) { }
|
||||||
public void onWorldEventFlag(ServerWorld world, BlockPos pos, int flag) { }
|
public void onWorldEventFlag(ServerWorld world, BlockPos pos, int flag) { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,3 +185,38 @@ __on_player_places_block(player, item_tuple, hand, block) ->
|
|||||||
print(' > count: '+count);
|
print(' > count: '+count);
|
||||||
print(' > nbt: '+nbt);
|
print(' > nbt: '+nbt);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
__on_player_takes_damage(player, amount, source, entity) ->
|
||||||
|
(
|
||||||
|
print('');
|
||||||
|
print('__on_player_takes_damage(player, amount, source, source_entity)');
|
||||||
|
print('player takes damage:');
|
||||||
|
print(' - player: '+player);
|
||||||
|
print(' - amount: '+str('%.2f',amount));
|
||||||
|
print(' - source: '+source);
|
||||||
|
print(' - source_entity: '+entity);
|
||||||
|
);
|
||||||
|
|
||||||
|
__on_player_deals_damage(player, amount, entity) ->
|
||||||
|
(
|
||||||
|
print('');
|
||||||
|
print('__on_player_deals_damage(player, amount, target)');
|
||||||
|
print('player deals damage:');
|
||||||
|
print(' - player: '+player);
|
||||||
|
print(' - amount: '+str('%.2f',amount));
|
||||||
|
print(' - target: '+entity);
|
||||||
|
);
|
||||||
|
|
||||||
|
__on_player_dies(player) ->
|
||||||
|
(
|
||||||
|
print('');
|
||||||
|
print('__on_player_dies(player)');
|
||||||
|
print('Player '+player+' dies.')
|
||||||
|
);
|
||||||
|
|
||||||
|
__on_player_respawns(player) ->
|
||||||
|
(
|
||||||
|
print('');
|
||||||
|
print('__on_player_respawns(player)');
|
||||||
|
print('Player '+player+' respawns.')
|
||||||
|
);
|
||||||
@@ -140,6 +140,7 @@
|
|||||||
"ServerPlayerEntity_scarpetEventMixin",
|
"ServerPlayerEntity_scarpetEventMixin",
|
||||||
"FallingBlockEntity_scarpetEventsMixin",
|
"FallingBlockEntity_scarpetEventsMixin",
|
||||||
"BlockItem_scarpetEventMixin",
|
"BlockItem_scarpetEventMixin",
|
||||||
|
"PlayerManager_scarpetEventsMixin",
|
||||||
|
|
||||||
"ChunkTicketManager_scarpetMixin",
|
"ChunkTicketManager_scarpetMixin",
|
||||||
"ServerChunkManager_scarpetMixin",
|
"ServerChunkManager_scarpetMixin",
|
||||||
|
|||||||
Reference in new issue
Block a user