Merge branch 'master' into 1.15

This commit is contained in:
gnembon committed 2019-09-04 22:06:05 -03:00
commit 2fcef289f0
10 files changed
+127 -33

No files matched your search

@@ -4,6 +4,7 @@ import carpet.script.CarpetContext;
import carpet.script.CarpetEventServer;
import carpet.script.ScriptHost;
import carpet.script.value.Value;
import net.minecraft.entity.damage.DamageSource;
import java.util.List;
@@ -13,8 +14,8 @@ public interface EntityInterface
//scarpet part
void onDeathCallback(String reason);
void setDeathCallback(CarpetContext cc, String function, List<Value> extraArgs);
void onDamageCallback();
void onDamageCallback(float amount, DamageSource source);
void setDamageCallback(CarpetContext cc, String function, List<Value> extraArgs);
void onRemovedCallback();
void setRemovedCallback(CarpetContext cc, String function, List<Value> extraArgs);
void setTickCallback(CarpetContext cc, String function, List<Value> extraArgs);
}
@@ -0,0 +1,7 @@
package carpet.fakes;
public interface ItemEntityInterface
{
int getAge();
int getPickupDelay();
}
@@ -0,0 +1,24 @@
package carpet.mixins;
import carpet.fakes.EntityInterface;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTracker;
import org.spongepowered.asm.mixin.Final;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(DamageTracker.class)
public class DamageTracker_scarpetEventMixin
{
@Shadow @Final private LivingEntity entity;
@Inject(method = "onDamage", at = @At("HEAD"))
private void onDamageTaken(DamageSource damageSource_1, float float_1, float float_2, CallbackInfo ci)
{
((EntityInterface)entity).onDamageCallback(float_2, damageSource_1);
}
}
@@ -8,6 +8,7 @@ import carpet.script.ScriptHost;
import carpet.script.value.Value;
import carpet.settings.CarpetSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import org.lwjgl.system.CallbackI;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -23,16 +24,11 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
@Shadow public boolean removed;
private CarpetEventServer.ScheduledCall deathCall;
private CarpetEventServer.ScheduledCall removeCall;
private CarpetEventServer.ScheduledCall tickCall;
private CarpetEventServer.ScheduledCall damageCall;
@Override
public void onDeathCallback(String reason)
{
if (deathCall != null)
{
CarpetServer.scriptServer.events.onEntityDeath(deathCall, (Entity)(Object)this, reason);
}
}
@Override
public void setDeathCallback(CarpetContext cc, String function, List<Value> extraArgs)
@@ -46,6 +42,47 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface
removeCall = CarpetServer.scriptServer.events.makeRemovedCall(cc, function, extraArgs);
}
@Override
public void setTickCallback(CarpetContext cc, String function, List<Value> extraArgs)
{
tickCall = CarpetServer.scriptServer.events.makeTickCall(cc, function, extraArgs);
}
@Override
public void setDamageCallback(CarpetContext cc, String function, List<Value> extraArgs)
{
damageCall = CarpetServer.scriptServer.events.makeDamageCall(cc, function, extraArgs);
}
@Override
public void onDeathCallback(String reason)
{
if (deathCall != null)
{
CarpetServer.scriptServer.events.onEntityDeath(deathCall, (Entity)(Object)this, reason);
}
}
@Override
public void onDamageCallback(float amount, DamageSource source)
{
if (damageCall != null)
{
CarpetServer.scriptServer.events.onEntityDamage(damageCall, (Entity)(Object)this, amount, source);
}
}
@Inject(method = "tick", at = @At("HEAD"))
private void onTickCall(CallbackInfo ci)
{
if (tickCall != null)
{
CarpetServer.scriptServer.events.onEntityTick(tickCall, (Entity) (Object) this);
}
}
@Inject(method = "remove", at = @At("HEAD"))
private void onRemove(CallbackInfo ci)
@@ -2,7 +2,7 @@ package carpet.mixins;
import carpet.settings.CarpetSettings;
import carpet.helpers.InventoryHelper;
import carpet.utils.IItemEntity;
import carpet.fakes.ItemEntityInterface;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
@@ -18,7 +18,8 @@ import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ItemEntity.class)
public abstract class ItemEntityMixin extends Entity implements IItemEntity {
public abstract class ItemEntityMixin extends Entity implements ItemEntityInterface
{
private static final int SHULKERBOX_MAX_STACK_AMOUNT = 64;
@Shadow private int age;
@@ -89,8 +90,8 @@ public abstract class ItemEntityMixin extends Entity implements IItemEntity {
selfStack.increment(amount);
self.setStack(selfStack);
this.pickupDelay = Math.max(((IItemEntity)other).getPickupDelay(), this.pickupDelay);
this.age = Math.min(((IItemEntity)other).getAge(), this.age);
this.pickupDelay = Math.max(((ItemEntityInterface)other).getPickupDelay(), this.pickupDelay);
this.age = Math.min(((ItemEntityInterface)other).getAge(), this.age);
otherStack.decrement(amount);
if (otherStack.isEmpty())
@@ -57,11 +57,12 @@ public abstract class World_tickMixin implements WorldInterface
@Redirect(method = "tickBlockEntities", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/entity/BlockEntity;hasWorld()Z"
target = "Lnet/minecraft/block/entity/BlockEntity;isInvalid()Z",
ordinal = 0
))
private boolean checkProcessTEs(BlockEntity blockEntity)
{
return blockEntity.hasWorld() && TickSpeed.process_entities;
return blockEntity.isInvalid() || !TickSpeed.process_entities;
}
@Inject(method = "tickBlockEntities", at = @At(
@@ -9,6 +9,7 @@ import carpet.script.value.StringValue;
import carpet.script.value.Value;
import carpet.settings.CarpetSettings;
import net.minecraft.block.BlockState;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.entity.Entity;
@@ -291,11 +292,7 @@ public class CarpetEventServer
ItemStack itemstack = player.getStackInHand(enumhand);
return Arrays.asList(
((c, t) -> new EntityValue(player)),
((c, t) -> ListValue.of(
new StringValue(Registry.ITEM.getId(itemstack.getItem()).getPath()),
new NumericValue(itemstack.getCount()),
new StringValue(itemstack.toTag(new CompoundTag()).toString())
)),
((c, t) -> ListValue.fromItemStack(itemstack)),
((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand"))
);
}, player::getCommandSource);
@@ -320,11 +317,7 @@ public class CarpetEventServer
Vec3d vec3d = hitRes.getPos().subtract(blockpos.getX(), blockpos.getY(), blockpos.getZ());
return Arrays.asList(
((c, t) -> new EntityValue(player)),
((c, t) -> ListValue.of(
new StringValue(Registry.ITEM.getId(itemstack.getItem()).getPath()),
new NumericValue(itemstack.getCount()),
new StringValue(itemstack.toTag(new CompoundTag()).toString())
)),
((c, t) -> ListValue.fromItemStack(itemstack)),
((c, t) -> new StringValue(enumhand == Hand.MAIN_HAND ? "mainhand" : "offhand")),
((c, t) -> new BlockValue(null, player.world, blockpos)),
((c, t) -> new StringValue(enumfacing.getName())),
@@ -390,6 +383,15 @@ public class CarpetEventServer
{
return makeEventCall(cc, function, extraArgs, 1);
}
public ScheduledCall makeTickCall(CarpetContext cc, String function, List<Value> extraArgs)
{
return makeEventCall(cc, function, extraArgs, 1);
}
public ScheduledCall makeDamageCall(CarpetContext cc, String function, List<Value> extraArgs)
{
return makeEventCall(cc, function, extraArgs, 3);
}
public void onEntityDeath(ScheduledCall call, Entity e, String reason)
@@ -400,5 +402,20 @@ public class CarpetEventServer
{
removeCall.execute(Collections.singletonList((c, t) -> new EntityValue(entity)));
}
public void onEntityTick(ScheduledCall tickCall, Entity entity)
{
tickCall.execute(Collections.singletonList((c, t) -> new EntityValue(entity)));
}
public void onEntityDamage(ScheduledCall call, Entity e, float amount, DamageSource source)
{
call.execute(Arrays.asList(
(c, t) -> new EntityValue(e),
(c, t) -> new NumericValue(amount),
(c, t) -> new StringValue(source.getName()),
(c, t) -> source.getAttacker()==null?Value.NULL:new EntityValue(source.getAttacker())
));
}
}
@@ -1,6 +1,7 @@
package carpet.script.value;
import carpet.fakes.EntityInterface;
import carpet.fakes.ItemEntityInterface;
import carpet.fakes.MobEntityInterface;
import carpet.helpers.Tracer;
import carpet.script.CarpetContext;
@@ -214,8 +215,9 @@ public class EntityValue extends Value
put("width", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).width));
put("eye_height", (e, a) -> new NumericValue(e.getEyeHeight(EntityPose.STANDING)));
put("age", (e, a) -> new NumericValue(e.age));
put("item", (e, a) -> (e instanceof ItemEntity)?new StringValue(((ItemEntity) e).getStack().getName().getString()):Value.NULL);
put("item", (e, a) -> (e instanceof ItemEntity)?ListValue.fromItemStack(((ItemEntity) e).getStack()):Value.NULL);
put("count", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntity) e).getStack().getCount()):Value.NULL);
put("pickup_delay", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntityInterface) e).getPickupDelay()):Value.NULL);
// ItemEntity -> despawn timer via ssGetAge
put("is_baby", (e, a) -> (e instanceof LivingEntity)?new NumericValue(((LivingEntity) e).isBaby()):Value.NULL);
put("target", (e, a) -> {
@@ -691,6 +693,13 @@ public class EntityValue extends Value
}
}); //requires mixing
put("pickup_delay", (e, v) ->
{
if (e instanceof ItemEntity)
{
((ItemEntity) e).setPickupDelay((int)NumericValue.asNumber(v).getLong());
}
});
// gamemode
// spectate
@@ -720,5 +729,7 @@ public class EntityValue extends Value
private static Map<String, Fluff.QuadConsumer<CarpetContext, Entity, String, List<Value>>> events = new HashMap<String, Fluff.QuadConsumer<CarpetContext, Entity, String, List<Value>>>() {{
put("on_death", (c, e, f, l) -> ((EntityInterface)e).setDeathCallback(c, f, l));
put("on_removed", (c, e, f, l) -> ((EntityInterface)e).setRemovedCallback(c, f, l));
put("on_tick", (c, e, f, l) -> ((EntityInterface)e).setTickCallback(c, f, l));
put("on_damage", (c, e, f, l) -> ((EntityInterface)e).setDamageCallback(c, f, l));
}};
}
@@ -1,6 +0,0 @@
package carpet.utils;
public interface IItemEntity {
int getAge();
int getPickupDelay();
}