tweaks to entity API code
This commit is contained in:
1 parent
1aa237379e
commit
1e9a8726be
6 files changed
+72
-44
No files matched your search
@@ -2661,7 +2661,7 @@ Adds a vector to the motion vector. Most realistic way to apply a force to an en
|
|||||||
|
|
||||||
### `modify(e, 'age', number)`
|
### `modify(e, 'age', number)`
|
||||||
|
|
||||||
Modifies entity's internal age counter. Fiddling with this will affect directly behaviours of complex
|
Modifies entity's internal age counter. Fiddling with this will affect directly AI behaviours of complex
|
||||||
entities, so use it with caution.
|
entities, so use it with caution.
|
||||||
|
|
||||||
### `modify(e, 'pickup_delay', number)`
|
### `modify(e, 'pickup_delay', number)`
|
||||||
@@ -2728,13 +2728,17 @@ Modifies gamemode of player to whatever string (case-insensitive) or number you
|
|||||||
* 2: adventure
|
* 2: adventure
|
||||||
* 3: spectator
|
* 3: spectator
|
||||||
|
|
||||||
### `modify(e, 'jumping', true/false?)`
|
### `modify(e, 'jumping', true/false)`
|
||||||
|
|
||||||
Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false.
|
Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false.
|
||||||
|
Note that jumping parameter can be fully controlled by the entity AI, so don't expect that this will have
|
||||||
|
a permanent effect. Use `'jump'` to make an entity jump once for sure.
|
||||||
|
|
||||||
|
Requires a living entity as an argument.
|
||||||
|
|
||||||
### `modify(e, 'jump'))`
|
### `modify(e, 'jump'))`
|
||||||
|
|
||||||
Will make the entity jump once only
|
Will make the entity jump once.
|
||||||
|
|
||||||
### `modify(e, 'silent', true/false)`
|
### `modify(e, 'silent', true/false)`
|
||||||
|
|
||||||
@@ -2744,9 +2748,6 @@ Will make the entity jump once only
|
|||||||
|
|
||||||
Will set mob on fire for `ticks` ticks. Set to 0 to extinguish.
|
Will set mob on fire for `ticks` ticks. Set to 0 to extinguish.
|
||||||
|
|
||||||
### `modify(e, 'age', age)`
|
|
||||||
|
|
||||||
|
|
||||||
## Entity Events
|
## Entity Events
|
||||||
|
|
||||||
There is a number of events that happen to entities that you can attach your own code to in the form of event handlers.
|
There is a number of events that happen to entities that you can attach your own code to in the form of event handlers.
|
||||||
@@ -3090,7 +3091,7 @@ And colors:
|
|||||||
* `e` - grEEn
|
* `e` - grEEn
|
||||||
* `v` - naVy blue
|
* `v` - naVy blue
|
||||||
* `k` - blaK
|
* `k` - blaK
|
||||||
* `#FFAACC` - arbitrary RGB color (1.16+), hex notation
|
* `#FFAACC` - arbitrary RGB color (1.16+), hex notation. Use uppercase for A-F symbols
|
||||||
|
|
||||||
Decorators (listed as extra argument after the component they would affect):
|
Decorators (listed as extra argument after the component they would affect):
|
||||||
* `'^<format> <text>'` - hover over tooltip text, appearing when hovering with your mouse over the text below.
|
* `'^<format> <text>'` - hover over tooltip text, appearing when hovering with your mouse over the text below.
|
||||||
|
|||||||
@@ -400,7 +400,7 @@ Adds a vector to the motion vector. Most realistic way to apply a force to an en
|
|||||||
|
|
||||||
### `modify(e, 'age', number)`
|
### `modify(e, 'age', number)`
|
||||||
|
|
||||||
Modifies entity's internal age counter. Fiddling with this will affect directly behaviours of complex
|
Modifies entity's internal age counter. Fiddling with this will affect directly AI behaviours of complex
|
||||||
entities, so use it with caution.
|
entities, so use it with caution.
|
||||||
|
|
||||||
### `modify(e, 'pickup_delay', number)`
|
### `modify(e, 'pickup_delay', number)`
|
||||||
@@ -470,10 +470,14 @@ Modifies gamemode of player to whatever string (case-insensitive) or number you
|
|||||||
### `modify(e, 'jumping', true/false)`
|
### `modify(e, 'jumping', true/false)`
|
||||||
|
|
||||||
Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false.
|
Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false.
|
||||||
|
Note that jumping parameter can be fully controlled by the entity AI, so don't expect that this will have
|
||||||
|
a permanent effect. Use `'jump'` to make an entity jump once for sure.
|
||||||
|
|
||||||
|
Requires a living entity as an argument.
|
||||||
|
|
||||||
### `modify(e, 'jump'))`
|
### `modify(e, 'jump'))`
|
||||||
|
|
||||||
Will make the entity jump once only
|
Will make the entity jump once.
|
||||||
|
|
||||||
### `modify(e, 'silent', true/false)`
|
### `modify(e, 'silent', true/false)`
|
||||||
|
|
||||||
@@ -483,8 +487,6 @@ Will make the entity jump once only
|
|||||||
|
|
||||||
Will set mob on fire for `ticks` ticks. Set to 0 to extinguish.
|
Will set mob on fire for `ticks` ticks. Set to 0 to extinguish.
|
||||||
|
|
||||||
### `modify(e, 'age', age)`
|
|
||||||
|
|
||||||
## Entity Events
|
## Entity Events
|
||||||
|
|
||||||
There is a number of events that happen to entities that you can attach your own code to in the form of event handlers.
|
There is a number of events that happen to entities that you can attach your own code to in the form of event handlers.
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package carpet.fakes;
|
||||||
|
|
||||||
|
public interface LivingEntityInterface
|
||||||
|
{
|
||||||
|
void doJumpCM(); // added CM suffix to remove potential collisions with other mods
|
||||||
|
boolean isJumpingCM();
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
import carpet.fakes.EntityInterface;
|
import carpet.fakes.EntityInterface;
|
||||||
|
import carpet.fakes.LivingEntityInterface;
|
||||||
import carpet.script.EntityEventsGroup;
|
import carpet.script.EntityEventsGroup;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
@@ -8,14 +9,19 @@ import net.minecraft.entity.LivingEntity;
|
|||||||
import net.minecraft.entity.damage.DamageSource;
|
import net.minecraft.entity.damage.DamageSource;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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.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;
|
||||||
|
|
||||||
@Mixin(LivingEntity.class)
|
@Mixin(LivingEntity.class)
|
||||||
public abstract class LivingEntity_scarpetEventsMixin extends Entity
|
public abstract class LivingEntity_scarpetEventsMixin extends Entity implements LivingEntityInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Shadow protected abstract void jump();
|
||||||
|
|
||||||
|
@Shadow protected boolean jumping;
|
||||||
|
|
||||||
public LivingEntity_scarpetEventsMixin(EntityType<?> type, World world)
|
public LivingEntity_scarpetEventsMixin(EntityType<?> type, World world)
|
||||||
{
|
{
|
||||||
super(type, world);
|
super(type, world);
|
||||||
@@ -26,4 +32,16 @@ public abstract class LivingEntity_scarpetEventsMixin extends Entity
|
|||||||
{
|
{
|
||||||
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, damageSource_1.name);
|
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, this, damageSource_1.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doJumpCM()
|
||||||
|
{
|
||||||
|
jump();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isJumpingCM()
|
||||||
|
{
|
||||||
|
return jumping;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package carpet.script.value;
|
|||||||
|
|
||||||
import carpet.fakes.EntityInterface;
|
import carpet.fakes.EntityInterface;
|
||||||
import carpet.fakes.ItemEntityInterface;
|
import carpet.fakes.ItemEntityInterface;
|
||||||
|
import carpet.fakes.LivingEntityInterface;
|
||||||
import carpet.fakes.MobEntityInterface;
|
import carpet.fakes.MobEntityInterface;
|
||||||
import carpet.helpers.Tracer;
|
import carpet.helpers.Tracer;
|
||||||
import carpet.patches.EntityPlayerMPFake;
|
import carpet.patches.EntityPlayerMPFake;
|
||||||
@@ -61,7 +62,7 @@ import java.util.function.Predicate;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
|
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
|
||||||
import static carpet.utils.MobAI.jump;
|
import static carpet.utils.MobAI.genericJump;
|
||||||
|
|
||||||
// TODO: decide whether copy(entity) should duplicate entity in the world.
|
// TODO: decide whether copy(entity) should duplicate entity in the world.
|
||||||
public class EntityValue extends Value
|
public class EntityValue extends Value
|
||||||
@@ -281,13 +282,13 @@ public class EntityValue extends Value
|
|||||||
put("sneaking", (e, a) -> e.isSneaking()?Value.TRUE:Value.FALSE);
|
put("sneaking", (e, a) -> e.isSneaking()?Value.TRUE:Value.FALSE);
|
||||||
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
|
put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE);
|
||||||
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
|
put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE);
|
||||||
/*put("jumping", (e, a) -> {
|
put("jumping", (e, a) -> {
|
||||||
if (e instanceof LivingEntity)
|
if (e instanceof LivingEntity)
|
||||||
{
|
{
|
||||||
return ((LivingEntity) e).getJumping()?Value.TRUE:Value.FALSE;
|
return ((LivingEntityInterface) e).isJumpingCM()?Value.TRUE:Value.FALSE;
|
||||||
}
|
}
|
||||||
return Value.NULL;
|
return Value.NULL;
|
||||||
});*/ //needs mixing
|
});
|
||||||
put("gamemode", (e, a) -> {
|
put("gamemode", (e, a) -> {
|
||||||
if (e instanceof ServerPlayerEntity)
|
if (e instanceof ServerPlayerEntity)
|
||||||
{
|
{
|
||||||
@@ -376,6 +377,7 @@ public class EntityValue extends Value
|
|||||||
StatusEffectInstance pe = ((LivingEntity) e).getStatusEffect(potion);
|
StatusEffectInstance pe = ((LivingEntity) e).getStatusEffect(potion);
|
||||||
return ListValue.of( new NumericValue(pe.getAmplifier()), new NumericValue(pe.getDuration()) );
|
return ListValue.of( new NumericValue(pe.getAmplifier()), new NumericValue(pe.getDuration()) );
|
||||||
});
|
});
|
||||||
|
|
||||||
put("health", (e, a) ->
|
put("health", (e, a) ->
|
||||||
{
|
{
|
||||||
if (e instanceof LivingEntity)
|
if (e instanceof LivingEntity)
|
||||||
@@ -531,8 +533,6 @@ public class EntityValue extends Value
|
|||||||
//((ServerWorld)e.getEntityWorld()).method_14178().sendToNearbyPlayers(e, new EntityVelocityUpdateS2CPacket(e));
|
//((ServerWorld)e.getEntityWorld()).method_14178().sendToNearbyPlayers(e, new EntityVelocityUpdateS2CPacket(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{
|
private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>() {{
|
||||||
put("remove", (entity, value) -> entity.remove());
|
put("remove", (entity, value) -> entity.remove());
|
||||||
put("age", (e, v) -> e.age = Math.abs((int)NumericValue.asNumber(v).getLong()) );
|
put("age", (e, v) -> e.age = Math.abs((int)NumericValue.asNumber(v).getLong()) );
|
||||||
@@ -896,25 +896,27 @@ public class EntityValue extends Value
|
|||||||
});
|
});
|
||||||
|
|
||||||
put("gamemode", (e,v)->{
|
put("gamemode", (e,v)->{
|
||||||
if(!(e instanceof ServerPlayerEntity)){
|
if(!(e instanceof ServerPlayerEntity)) return;
|
||||||
return;
|
GameMode toSet = v instanceof NumericValue ?
|
||||||
}
|
GameMode.byId(((NumericValue) v).getInt(), null) :
|
||||||
switch(v.getString().toLowerCase()){
|
GameMode.byName(v.getString().toLowerCase(Locale.ROOT), null);
|
||||||
case "survival": case "0":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);break;
|
if (toSet != null) ((ServerPlayerEntity) e).setGameMode(toSet);
|
||||||
case "creative": case "1":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);break;
|
|
||||||
case "adventure": case "2":((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);break;
|
|
||||||
case "spectator": case "3":((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);break;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
put("jumping",(e,v)->{
|
put("jumping",(e,v)->{
|
||||||
if(!(e instanceof LivingEntity)) return;
|
if(!(e instanceof LivingEntity)) return;
|
||||||
|
|
||||||
((LivingEntity) e).setJumping(v.getBoolean());
|
((LivingEntity) e).setJumping(v.getBoolean());
|
||||||
});
|
});
|
||||||
|
|
||||||
put("jump",(e,v)->{
|
put("jump",(e,v)->{
|
||||||
jump((LivingEntity)e);
|
if (e instanceof LivingEntity)
|
||||||
|
{
|
||||||
|
((LivingEntityInterface)e).doJumpCM();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
genericJump(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
put("silent",(e,v)->{
|
put("silent",(e,v)->{
|
||||||
@@ -933,10 +935,6 @@ public class EntityValue extends Value
|
|||||||
e.setFireTicks((int)NumericValue.asNumber(v).getLong());
|
e.setFireTicks((int)NumericValue.asNumber(v).getLong());
|
||||||
});
|
});
|
||||||
|
|
||||||
put("age",(e,v)->{
|
|
||||||
e.age=(int)NumericValue.asNumber(v).getLong();
|
|
||||||
});
|
|
||||||
|
|
||||||
// gamemode [check]
|
// gamemode [check]
|
||||||
// spectate [check]
|
// spectate [check]
|
||||||
// "fire" [check]
|
// "fire" [check]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import net.minecraft.entity.EntityType;
|
|||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.entity.effect.StatusEffects;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.tag.FluidTags;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
@@ -98,23 +99,24 @@ public class MobAI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void jump(LivingEntity e){//Most *REDACTED* up code in the world
|
/**
|
||||||
|
* Not a replacement for living entity jump() - this barely is to allow other entities that can't jump in vanilla to 'jump'
|
||||||
|
* @param e
|
||||||
|
*/
|
||||||
|
public static void genericJump(Entity e)
|
||||||
|
{
|
||||||
|
if (!e.onGround && !e.isInFluid(FluidTags.WATER) && !e.isInLava()) return;
|
||||||
float m = e.world.getBlockState(new BlockPos(e)).getBlock().getJumpVelocityMultiplier();
|
float m = e.world.getBlockState(new BlockPos(e)).getBlock().getJumpVelocityMultiplier();
|
||||||
float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().y1 - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier();
|
float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().y1 - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier();
|
||||||
float JumpVelocityMultiplier= (double)m == 1.0D ? g : m;
|
float jumpVelocityMultiplier = (double) m == 1.0D ? g : m;
|
||||||
|
float jumpStrength = (0.42F * jumpVelocityMultiplier);
|
||||||
float f = (0.42F * JumpVelocityMultiplier);
|
|
||||||
if (e.hasStatusEffect(StatusEffects.JUMP_BOOST)) {
|
|
||||||
f += 0.1F * (float)(e.getStatusEffect(StatusEffects.JUMP_BOOST).getAmplifier() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3d vec3d = e.getVelocity();
|
Vec3d vec3d = e.getVelocity();
|
||||||
e.setVelocity(vec3d.x, f, vec3d.z);
|
e.setVelocity(vec3d.x, jumpStrength, vec3d.z);
|
||||||
if (e.isSprinting()) {
|
if (e.isSprinting())
|
||||||
|
{
|
||||||
float u = e.yaw * 0.017453292F;
|
float u = e.yaw * 0.017453292F;
|
||||||
e.setVelocity(e.getVelocity().add((-MathHelper.sin(g) * 0.2F), 0.0D, (MathHelper.cos(u) * 0.2F)));
|
e.setVelocity(e.getVelocity().add((-MathHelper.sin(g) * 0.2F), 0.0D, (MathHelper.cos(u) * 0.2F)));
|
||||||
}
|
}
|
||||||
|
|
||||||
e.velocityDirty = true;
|
e.velocityDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user