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
+154
-4
No files matched your search
@@ -5,6 +5,7 @@ import carpet.script.EntityEventsGroup;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.damage.DamageTracker;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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.callback.CallbackInfo;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_DEALS_DAMAGE;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_TAKES_DAMAGE;
|
||||
|
||||
@Mixin(DamageTracker.class)
|
||||
public class DamageTracker_scarpetEventMixin
|
||||
public abstract class DamageTracker_scarpetEventMixin
|
||||
{
|
||||
@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)
|
||||
{
|
||||
((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.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.STATISTICS;
|
||||
|
||||
@@ -61,6 +62,10 @@ public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
|
||||
private void onDeathEvent(DamageSource source, CallbackInfo ci)
|
||||
{
|
||||
((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(
|
||||
|
||||
@@ -12,6 +12,7 @@ import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@@ -479,6 +480,53 @@ public class CarpetEventServer
|
||||
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)
|
||||
{
|
||||
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 onBlockPlaced(ServerPlayerEntity player, BlockPos pos, Hand enumhand, ItemStack itemstack) { }
|
||||
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 onWorldEventFlag(ServerWorld world, BlockPos pos, int flag) { }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user