Browse Source

human statues

Kajetan Johannes Hammerle 4 years ago
parent
commit
082cf8b810

+ 26 - 7
src/main/java/me/km/entities/EntityHuman.java

@@ -1,7 +1,7 @@
 package me.km.entities;
 
 import me.km.Server;
-import me.km.overrides.ModEntityPlayerMP;
+import me.km.utils.ReflectionUtils;
 import net.minecraft.entity.Entity;
 import net.minecraft.entity.CreatureEntity;
 import net.minecraft.entity.EntitySize;
@@ -30,6 +30,7 @@ public class EntityHuman extends CreatureEntity {
     private static final DataParameter<String> SKIN_NAME = EntityDataManager.createKey(EntityHuman.class, DataSerializers.STRING);
     private static final DataParameter<Float> SCALE = EntityDataManager.createKey(EntityHuman.class, DataSerializers.FLOAT);
     private static final DataParameter<Boolean> SLIM = EntityDataManager.createKey(EntityHuman.class, DataSerializers.BOOLEAN);
+    private static final DataParameter<Boolean> STATUE = EntityDataManager.createKey(EntityHuman.class, DataSerializers.BOOLEAN);
 
     private final float originalWidth;
     private final float originalHeight;
@@ -48,11 +49,22 @@ public class EntityHuman extends CreatureEntity {
         this.getDataManager().register(SKIN_NAME, "Steve");
         this.getDataManager().register(SCALE, 1.0f);
         this.getDataManager().register(SLIM, false);
+        this.getDataManager().register(STATUE, false);
+    }
+
+    public boolean isStatue() {
+        return this.getDataManager().get(STATUE);
+    }
+
+    public void setStatue(boolean statue) {
+        this.getDataManager().set(STATUE, statue);
+        if(!world.isRemote) {
+            ReflectionUtils.getGoals(goalSelector).clear();
+            ReflectionUtils.getGoals(targetSelector).clear();
+            registerGoals();
+        }
     }
 
-    // -------------------------------------------------------------------------
-    // size modifier
-    // -------------------------------------------------------------------------
     public boolean isSlim() {
         return this.getDataManager().get(SLIM);
     }
@@ -82,11 +94,11 @@ public class EntityHuman extends CreatureEntity {
         return this.getDataManager().get(SKIN_NAME);
     }
 
-    // -------------------------------------------------------------------------
-    // texture stuff
-    // -------------------------------------------------------------------------
     @OnlyIn(Dist.CLIENT)
     public ResourceLocation getTexture() {
+        if(isStatue()) {
+            return HumanSkinLoader.GREY_INSTANCE.getTexture(getSkinName());
+        }
         return HumanSkinLoader.INSTANCE.getTexture(getSkinName());
     }
 
@@ -102,6 +114,9 @@ public class EntityHuman extends CreatureEntity {
         if(com.contains("Slim")) {
             setSlim(com.getBoolean("Slim"));
         }
+        if(com.contains("Statue")) {
+            setStatue(com.getBoolean("Statue"));
+        }
     }
 
     @Override
@@ -110,6 +125,7 @@ public class EntityHuman extends CreatureEntity {
         com.putString("HumanName", getSkinName());
         com.putFloat("Scale", getScale());
         com.putBoolean("Slim", isSlim());
+        com.putBoolean("Statue", isStatue());
     }
 
     @Override
@@ -138,6 +154,9 @@ public class EntityHuman extends CreatureEntity {
 
     @Override
     protected void registerGoals() {
+        if(isStatue()) {
+            return;
+        }
         this.goalSelector.addGoal(0, new SwimGoal(this));
         this.goalSelector.addGoal(1, new LookAtGoal(this, PlayerEntity.class, 6.0F));
         this.goalSelector.addGoal(2, new LookRandomlyGoal(this));

+ 25 - 5
src/main/java/me/km/entities/HumanSkinLoader.java

@@ -16,7 +16,8 @@ import org.apache.logging.log4j.LogManager;
 
 @OnlyIn(Dist.CLIENT)
 public class HumanSkinLoader {
-    public final static HumanSkinLoader INSTANCE = new HumanSkinLoader();
+    public final static HumanSkinLoader INSTANCE = new HumanSkinLoader(false);
+    public final static HumanSkinLoader GREY_INSTANCE = new HumanSkinLoader(true);
 
     private static final ResourceLocation TEXTURE_STEVE = new ResourceLocation("textures/entity/steve.png");
 
@@ -24,8 +25,11 @@ public class HumanSkinLoader {
     private final HashSet<String> loading = new HashSet<>();
 
     private final TextureManager manager = Minecraft.getInstance().getRenderManager().textureManager;
+    
+    private final boolean grey;
 
-    private HumanSkinLoader() {
+    private HumanSkinLoader(boolean grey) {
+        this.grey = grey;
     }
 
     public ResourceLocation getTexture(String name) {
@@ -35,15 +39,15 @@ public class HumanSkinLoader {
         }
         if(loading.add(name)) {
             downloadSkin(name, image -> {
-                ResourceLocation rloc = manager.getDynamicTextureLocation("skin_" + name.toLowerCase(), new DynamicTexture(image));
+                ResourceLocation rloc = manager.getDynamicTextureLocation("skin_grey_" + name.toLowerCase(), new DynamicTexture(image));
                 skins.put(name, rloc);
                 loading.remove(name);
-            });
+            }, grey);
         }
         return TEXTURE_STEVE;
     }
 
-    private void downloadSkin(String name, Consumer<NativeImage> delayed) {
+    private void downloadSkin(String name, Consumer<NativeImage> delayed, boolean grey) {
         new Thread(() -> {
             HttpURLConnection httpurlconnection = null;
             try {
@@ -70,6 +74,22 @@ public class HumanSkinLoader {
                 }
 
                 NativeImage image = convert(NativeImage.read(httpurlconnection.getInputStream()));
+                if(grey) {
+                    for(int x = 0; x < image.getWidth(); x++) {
+                        for(int y = 0; y < image.getHeight(); y++) {
+                            int c = image.getPixelRGBA(x, y);
+                            int r = (c >> 0) & 0xFF;
+                            int g = (c >> 8) & 0xFF;
+                            int b = (c >> 16) & 0xFF;
+                            int a = (c >> 24) & 0xFF;
+
+                            int mix = (int) (r * 0.3 + g * 0.6 + b * 0.1);
+
+                            c = (mix << 0) | (mix << 8) | (mix << 16) | (a << 24);
+                            image.setPixelRGBA(x, y, c);
+                        }
+                    }
+                }
                 Minecraft.getInstance().enqueue(() -> delayed.accept(image));
             } catch(Exception ex) {
                 LogManager.getLogger().warn("Error occurred when downloading skin, however, skin servers seem to be up.");

+ 20 - 0
src/main/java/me/km/entities/ModelHuman.java

@@ -6,4 +6,24 @@ public class ModelHuman extends PlayerModel<EntityHuman> {
     public ModelHuman(float modelSize, boolean smallArmsIn) {
         super(modelSize, smallArmsIn);
     }
+
+    @Override
+    public void setRotationAngles(EntityHuman h, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
+        super.setRotationAngles(h, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
+        if(h.isStatue()) {
+            bipedLeftArm.rotateAngleX = 0.0f;
+            bipedLeftArm.rotateAngleY = 0.0f;
+            bipedLeftArm.rotateAngleZ = 0.0f;
+            bipedRightArm.rotateAngleX = 0.0f;
+            bipedRightArm.rotateAngleY = 0.0f;
+            bipedRightArm.rotateAngleZ = 0.0f;
+            
+            bipedLeftArmwear.rotateAngleX = 0.0f;
+            bipedLeftArmwear.rotateAngleY = 0.0f;
+            bipedLeftArmwear.rotateAngleZ = 0.0f;
+            bipedRightArmwear.rotateAngleX = 0.0f;
+            bipedRightArmwear.rotateAngleY = 0.0f;
+            bipedRightArmwear.rotateAngleZ = 0.0f;
+        }
+    }
 }

+ 5 - 6
src/main/java/me/km/snuviscript/commands/EntityCommands.java

@@ -6,7 +6,6 @@ import me.km.scheduler.SnuviScheduler;
 import static me.km.snuviscript.commands.CommandUtils.getNamedClass;
 import me.km.utils.Location;
 import me.km.utils.Mapper;
-import me.km.utils.ReflectionUtils;
 import me.km.utils.Utils;
 import net.minecraft.enchantment.EnchantmentHelper;
 import net.minecraft.entity.*;
@@ -20,6 +19,7 @@ import net.minecraft.inventory.EquipmentSlotType;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompoundNBT;
 import net.minecraft.nbt.JsonToNBT;
+import net.minecraft.network.play.server.SEntityPacket;
 import net.minecraft.potion.Effect;
 import net.minecraft.potion.EffectInstance;
 import net.minecraft.potion.PotionUtils;
@@ -28,6 +28,7 @@ import net.minecraft.util.DamageSource;
 import net.minecraft.util.Direction;
 import net.minecraft.util.ResourceLocation;
 import net.minecraft.util.math.BlockPos;
+import net.minecraft.util.math.MathHelper;
 import net.minecraft.util.math.Vec3d;
 import net.minecraft.util.text.StringTextComponent;
 import net.minecraft.world.World;
@@ -145,11 +146,9 @@ public class EntityCommands {
                     ServerWorld ws = (ServerWorld) l.getWorld();
                     ent.changeDimension(ws.getDimension().getType());
                 }
-                if(l.getYaw() != 0 && l.getPitch() != 0) {
-                    ent.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
-                } else {
-                    ent.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), ent.rotationYaw, ent.rotationPitch);
-                }
+                float yaw = l.getYaw() != 0.0f ? l.getYaw() : ent.rotationYaw;
+                float pitch = l.getPitch() != 0.0f ? l.getPitch() : ent.rotationPitch;
+                ent.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), yaw, pitch);
             }
         });
         sm.registerConsumer("entity.setequip", (sc, in) -> {

+ 3 - 0
src/main/java/me/km/snuviscript/commands/HumanCommands.java

@@ -16,6 +16,9 @@ public class HumanCommands {
             w.addEntity(h);
             return h;
         });
+        sm.registerConsumer("human.setstatue", (sc, in) -> {
+            ((EntityHuman) in[0].get(sc)).setStatue(in[1].getBoolean(sc));
+        });
         sm.registerConsumer("human.setskin", (sc, in) -> {
             ((EntityHuman) in[0].get(sc)).setSkinName(in[1].getString(sc));
         });

+ 1 - 1
src/main/resources/META-INF/mods.toml

@@ -2,7 +2,7 @@ modLoader="javafml"
 loaderVersion="[31,)"
 [[mods]]
 modId="km"
-version="0.0.43"
+version="0.0.44"
 displayName="Kajetans Mod"
 credits="kajetanjohannes"
 authors="kajetanjohannes"