Merge branch 'master' into 1.16

This commit is contained in:
gnembon committed 2020-07-14 00:05:35 -03:00
commit 39a85976fd
7 files changed
+28 -19

No files matched your search

@@ -24,7 +24,7 @@ public abstract class DamageTracker_scarpetEventMixin
@Inject(method = "onDamage", at = @At("HEAD"))
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, float_2, damageSource_1);
if (entity instanceof ServerPlayerEntity && PLAYER_TAKES_DAMAGE.isNeeded())
{
PLAYER_TAKES_DAMAGE.onDamage(entity, float_2, damageSource_1);
@@ -18,7 +18,7 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
@Shadow private int netherPortalCooldown;
private boolean permanentVehicle;
private final EntityEventsGroup events = new EntityEventsGroup();
private final EntityEventsGroup events = new EntityEventsGroup((Entity) (Object)this);
@Override
public EntityEventsGroup getEventContainer()
@@ -65,14 +65,14 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
@Inject(method = "tick", at = @At("HEAD"))
private void onTickCall(CallbackInfo ci)
{
events.onEvent(EntityEventsGroup.EntityEventType.ON_TICK, (Entity) (Object) this);
events.onEvent(EntityEventsGroup.EntityEventType.ON_TICK);
}
@Inject(method = "remove", at = @At("HEAD"))
private void onRemove(CallbackInfo ci)
{
if (!removed) events.onEvent(EntityEventsGroup.EntityEventType.ON_REMOVED, (Entity) (Object) this);
if (!removed) events.onEvent(EntityEventsGroup.EntityEventType.ON_REMOVED);
}
@@ -23,6 +23,6 @@ public abstract class FallingBlockEntity_scarpetEventsMixin extends Entity
private void onTickCall(CallbackInfo ci)
{
// calling extra on_tick because falling blocks do not fall back to super tick call
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_TICK, this);
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_TICK);
}
}
@@ -1,6 +1,5 @@
package carpet.mixins;
import carpet.CarpetSettings;
import carpet.fakes.EntityInterface;
import carpet.fakes.LivingEntityInterface;
import carpet.script.EntityEventsGroup;
@@ -8,17 +7,12 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntity.class)
public abstract class LivingEntity_scarpetEventsMixin extends Entity implements LivingEntityInterface
@@ -36,7 +30,7 @@ public abstract class LivingEntity_scarpetEventsMixin extends Entity implements
@Inject(method = "onDeath", at = @At("HEAD"))
private void onDeathCall(DamageSource damageSource_1, CallbackInfo ci)
{
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, damageSource_1.name);
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, damageSource_1.name);
}
@Override
@@ -72,7 +72,7 @@ public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity
@Inject(method = "onDeath", at = @At("HEAD"))
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, source.name);
if (PLAYER_DIES.isNeeded())
{
PLAYER_DIES.onPlayerEvent((ServerPlayerEntity) (Object)this);
@@ -1,6 +1,7 @@
package carpet.script;
import carpet.CarpetServer;
import carpet.CarpetSettings;
import carpet.script.exception.InternalExpressionException;
import carpet.script.value.BlockValue;
import carpet.script.value.EntityValue;
@@ -88,21 +89,33 @@ public class CarpetEventServer
this.dueTime = dueTime;
}
/**
* used in scheduled calls
*/
public void execute()
{
CarpetServer.scriptServer.runas(ctx.origin, ctx.s, host, function, lazify(args));
}
public void execute(List<Value> args)
/**
* Used in entity events
* @param asSource - entity command source
* @param args = options
*/
public void execute(ServerCommandSource asSource, List<Value> args)
{
if (this.args == null || this.args.isEmpty())
CarpetServer.scriptServer.runas(ctx.origin, ctx.s, host, function, lazify(args));
CarpetServer.scriptServer.runas(
ctx.origin, asSource.withLevel(CarpetSettings.runPermissionLevel),
host, function, lazify(args));
else
{
List<Value> combinedArgs = new ArrayList<>();
combinedArgs.addAll(args);
combinedArgs.addAll(this.args);
CarpetServer.scriptServer.runas(ctx.origin, ctx.s, host, function, lazify(combinedArgs));
CarpetServer.scriptServer.runas(
ctx.origin, asSource.withLevel(CarpetSettings.runPermissionLevel),
host, function, lazify(combinedArgs));
}
}
private List<LazyValue> lazify(List<Value> args)
@@ -22,12 +22,14 @@ import java.util.stream.Collectors;
public class EntityEventsGroup
{
private final Map<EntityEventType, Map<String, CarpetEventServer.ScheduledCall>> actions;
public EntityEventsGroup()
private Entity entity;
public EntityEventsGroup(Entity e)
{
actions = new EnumMap<>(EntityEventType.class);
entity = e;
}
public void onEvent(EntityEventType type, Entity entity, Object ... args)
public void onEvent(EntityEventType type, Object... args)
{
if (actions.isEmpty()) return; // most of the cases, trying to be nice
Map<String, CarpetEventServer.ScheduledCall> actionSet = actions.get(type);
@@ -116,7 +118,7 @@ public class EntityEventsGroup
public void call(CarpetEventServer.ScheduledCall tickCall, Entity entity, Object ... args)
{
assert args.length == argcount-1;
tickCall.execute(makeArgs(entity, args));
tickCall.execute(entity.getCommandSource(), makeArgs(entity, args));
}
protected List<Value> makeArgs(Entity entity, Object ... args)
{