Procházet zdrojové kódy

fixed nobody / human spawning on server and client side

Kajetan Johannes Hammerle před 3 roky
rodič
revize
59484b0809

+ 15 - 1
src/main/java/me/km/entities/EntityHuman.java

@@ -12,6 +12,7 @@ import net.minecraft.entity.ai.attributes.Attributes;
 import net.minecraft.entity.ai.goal.LookAtGoal;
 import net.minecraft.entity.ai.goal.LookRandomlyGoal;
 import net.minecraft.entity.ai.goal.SwimGoal;
+import net.minecraft.entity.monster.MonsterEntity;
 import net.minecraft.entity.player.PlayerEntity;
 import net.minecraft.nbt.CompoundNBT;
 import net.minecraft.network.datasync.DataParameter;
@@ -44,6 +45,18 @@ public class EntityHuman extends CreatureEntity {
         size = ModEntities.HUMAN.getSize();
     }
 
+    @Override
+    public void remove() {
+        super.remove();
+        System.out.println("remove human");
+    }
+
+    @Override
+    public void onDeath(DamageSource cause) {
+        super.onDeath(cause);
+        System.out.println("human death");
+    }
+
     @Override
     protected void registerData() {
         super.registerData();
@@ -164,7 +177,8 @@ public class EntityHuman extends CreatureEntity {
     }
 
     public static AttributeModifierMap.MutableAttribute getAttributes() {
-        return AttributeModifierMap.createMutableAttribute()
+        return MonsterEntity.func_234295_eP_()
+                .createMutableAttribute(Attributes.MAX_HEALTH, 20.0)
                 .createMutableAttribute(Attributes.ATTACK_DAMAGE, 1)
                 .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.1)
                 .createMutableAttribute(Attributes.ATTACK_SPEED);

+ 6 - 0
src/main/java/me/km/entities/EntityNobody.java

@@ -4,6 +4,8 @@ import java.util.Collections;
 import net.minecraft.entity.Entity;
 import net.minecraft.entity.EntityType;
 import net.minecraft.entity.LivingEntity;
+import net.minecraft.entity.ai.attributes.AttributeModifierMap;
+import net.minecraft.entity.ai.attributes.Attributes;
 import net.minecraft.inventory.EquipmentSlotType;
 import net.minecraft.item.ItemStack;
 import net.minecraft.util.DamageSource;
@@ -14,6 +16,10 @@ public class EntityNobody extends LivingEntity {
     public EntityNobody(EntityType<EntityNobody> type, World p_i48577_2_) {
         super(type, p_i48577_2_);
     }
+    
+    public static AttributeModifierMap.MutableAttribute getAttributes() {
+        return LivingEntity.registerAttributes().createMutableAttribute(Attributes.MAX_HEALTH, 10.0);
+    }
 
     @Override
     public boolean attackEntityFrom(DamageSource source, float amount) {

+ 3 - 2
src/main/java/me/km/entities/ModEntities.java

@@ -13,12 +13,12 @@ import net.minecraftforge.registries.IForgeRegistry;
 public class ModEntities {
     public static final EntityType<EntityHuman> HUMAN
             = (EntityType<EntityHuman>) EntityType.Builder.create(EntityHuman::new, EntityClassification.CREATURE)
-                    .size(0.6f, 1.8f)
+                    .size(0.6f, 1.8f).trackingRange(10)
                     .build(String.format("%s:human", KajetansMod.MODID))
                     .setRegistryName(KajetansMod.MODID, "human");
     public static final EntityType<EntityNobody> NOBODY
             = (EntityType<EntityNobody>) EntityType.Builder.create(EntityNobody::new, EntityClassification.MISC)
-                    .size(0.5f, 0.5f)
+                    .size(0.5f, 0.5f).trackingRange(10)
                     .build(String.format("%s:nobody", KajetansMod.MODID))
                     .setRegistryName(KajetansMod.MODID, "nobody");
 
@@ -30,6 +30,7 @@ public class ModEntities {
         r.register(NOBODY);
         
         GlobalEntityTypeAttributes.put(HUMAN, EntityHuman.getAttributes().create());
+        GlobalEntityTypeAttributes.put(NOBODY, EntityNobody.getAttributes().create());
     }
 
     @OnlyIn(Dist.CLIENT)

+ 17 - 16
src/main/java/me/km/snuviscript/commands/EntityCommands.java

@@ -225,27 +225,28 @@ public class EntityCommands {
             ((ItemEntity) in[0].get(sc)).setPickupDelay(in[1].getInt(sc));
         });
         sm.registerFunction("entity.spawn", (sc, in) -> {
-            ResourceLocation rl = new ResourceLocation(in[0].getString(sc));
+            ResourceLocation type = new ResourceLocation(in[0].getString(sc));
             Location l = (Location) in[1].get(sc);
+            if(!World.isInvalidPosition(l.getBlockPos())) {
+                return null;
+            }
+            CompoundNBT nbt = in.length >= 3 ? JsonToNBT.getTagFromJson(in[2].getString(sc)) : new CompoundNBT();
+            nbt.putString("id", type.toString());
             ServerWorld sw = (ServerWorld) l.getWorld();
-
-            CompoundNBT compoundnbt = in.length >= 3 ? JsonToNBT.getTagFromJson(in[2].getString(sc)) : new CompoundNBT();
-            compoundnbt.putString("id", rl.toString());
-            if(EntityType.getKey(EntityType.LIGHTNING_BOLT).equals(rl)) {
-                LightningBoltEntity ent = EntityType.LIGHTNING_BOLT.create(sw);
-                ent.moveForced(l.getPos());
-                sw.addEntity(ent);
+            Entity ent = EntityType.loadEntityAndExecute(nbt, sw, (e) -> {
+                e.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), e.rotationYaw, e.rotationPitch);
+                return e;
+            });
+            if(ent == null) {
                 return ent;
             }
-
-            Entity entity = EntityType.loadEntityAndExecute(compoundnbt, sw, (ent) -> {
-                ent.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), ent.rotationYaw, ent.rotationPitch);
-                return sw.summonEntity(ent) ? ent : null;
-            });
-            if(entity != null && entity instanceof MobEntity) {
-                ((MobEntity) entity).onInitialSpawn(sw, sw.getDifficultyForLocation(entity.getPosition()), SpawnReason.COMMAND, null, null);
+            if(ent instanceof MobEntity) {
+                ((MobEntity) ent).onInitialSpawn(sw, sw.getDifficultyForLocation(ent.getPosition()), SpawnReason.COMMAND, null, null);
             }
-            return entity;
+            if(!sw.func_242106_g(ent)) {
+                return null;
+            }
+            return ent;
         });
         sm.registerFunction("entity.near", (sc, in) -> {
             Object o = in[0].get(sc);

+ 2 - 2
src/main/java/me/km/snuviscript/commands/WorldCommands.java

@@ -17,8 +17,8 @@ public class WorldCommands {
         sm.registerAlias("players.toworldlist", "world.getplayers");
         sm.registerFunction("world.get", (sc, in) -> Utils.getWorldFromName(server, in[0].getString(sc)));
         sm.registerFunction("world.getname", (sc, in) -> Utils.getWorldName((World) in[0].get(sc)));
-        sm.registerConsumer("world.setdiffi", (sc, in) -> {
-            server.setDifficultyForAllWorlds(Difficulty.valueOf(in[1].getString(sc).toUpperCase()), true);
+        sm.registerConsumer("world.setdifficulty", (sc, in) -> {
+            server.setDifficultyForAllWorlds(Difficulty.valueOf(in[0].getString(sc).toUpperCase()), true);
         });
         sm.registerConsumer("world.setspawn", (sc, in) -> {
             Location l = ((Location) in[0].get(sc));