Skip to content

Commit

Permalink
wolf suit!
Browse files Browse the repository at this point in the history
I blame you, M
  • Loading branch information
techno-sam committed Oct 14, 2023
1 parent 45f556c commit 12687b2
Show file tree
Hide file tree
Showing 28 changed files with 367 additions and 80 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ run/

# nano

*.swp
*.swp

# Other
/src/main/resources/assets/server_mobs/textures/entity/crocodile.png
/src/main/resources/assets/minecraft/textures/entity/wolf/
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.slimeist.server_mobs.api;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.slimeist.server_mobs.api.compat.auto_host.ResendRPCommand;
import eu.pb4.polymer.api.resourcepack.PolymerRPUtils;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.command.ReloadCommand;
import net.minecraft.server.command.ServerCommandSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

public class ServerMobsApiMod implements DedicatedServerModInitializer {

Expand Down Expand Up @@ -37,6 +43,12 @@ public void onInitializeServer() {
});
}
});
if (FabricLoader.getInstance().isModLoaded("polymer-autohost")) {
CommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess, environment) -> {
Supplier<Supplier<LiteralArgumentBuilder<ServerCommandSource>>> supplier = () -> ResendRPCommand::register;
dispatcher.register(supplier.get().get());
}));
}
}

public static boolean forceRPBuild() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.slimeist.server_mobs.api.compat.auto_host;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import eu.pb4.polymer.api.resourcepack.PolymerRPUtils;
import eu.pb4.polymer.autohost.impl.AutoHost;
import eu.pb4.polymer.autohost.impl.WebServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;

public class ResendRPCommand {
public static LiteralArgumentBuilder<ServerCommandSource> register() {
return CommandManager.literal("resend_resourcepack")
.requires(cs -> cs.hasPermissionLevel(2))
.executes(ctx -> {
boolean required = AutoHost.config.require || PolymerRPUtils.isRequired();;
for (ServerPlayerEntity player : ctx.getSource().getServer().getPlayerManager().getPlayerList()) {
player.sendResourcePackUrl(WebServer.fullAddress, WebServer.hash, required, AutoHost.message);
}
ctx.getSource().sendFeedback(Text.literal("Sent resourcepack to all players"), false);
return 1;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ServerMobsConfig {
public boolean doCrocodileSpawning = true;
public boolean isCrocodileFluteEnabled = true;
public boolean isCrocodileArmorEnabled = true;
public boolean isWolfArmorEnabled = true;

public static ServerMobsConfig loadConfig(File file) {
ServerMobsConfig config;
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/com/slimeist/server_mobs/ServerMobsMod.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.slimeist.server_mobs;

import com.slimeist.server_mobs.api.ServerMobsApiMod;
import com.slimeist.server_mobs.api.server_rendering.model.ServerEntityModelLoader;
import com.slimeist.server_mobs.blocks.CrocodileFluteBlock;
import com.slimeist.server_mobs.entities.CrocodileEntity;
Expand Down Expand Up @@ -29,7 +28,6 @@
import net.minecraft.tag.BiomeTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -129,6 +127,16 @@ private static CustomArmorItem crocodileArmor(Item armorBase) {
public static final CustomArmorItem CROCODILE_HIDE_LEGGINGS = crocodileArmor(Items.LEATHER_LEGGINGS);
public static final CustomArmorItem CROCODILE_HIDE_BOOTS = crocodileArmor(Items.LEATHER_BOOTS);


private static CustomArmorItem wolfArmor(Item armorBase) {
return new CustomArmorItem((ArmorItem) armorBase, ArmorMaterials.CHAIN, new FabricItemSettings().group(ItemGroup.COMBAT), !getConfig().isWolfArmorEnabled);
}

public static final WolfHeadArmorItem WOLF_HEAD = new WolfHeadArmorItem((ArmorItem) Items.LEATHER_HELMET, Items.SLIME_BALL, ArmorMaterials.CHAIN, new FabricItemSettings().group(ItemGroup.COMBAT));
public static final CustomArmorItem WOLF_SUIT_CHESTPLATE = wolfArmor(Items.LEATHER_CHESTPLATE);
public static final CustomArmorItem WOLF_SUIT_LEGGINGS = wolfArmor(Items.LEATHER_LEGGINGS);
public static final CustomArmorItem WOLF_SUIT_BOOTS = wolfArmor(Items.LEATHER_BOOTS);

private static Path getConfigPath() {
return FabricLoader.getInstance().getConfigDir().resolve("server_mobs.json");
}
Expand Down Expand Up @@ -175,6 +183,20 @@ public void onInitializeServer() {
CROCODILE_HIDE_LEGGINGS.setCustomArmorColor(crocodileArmorModel.value());
CROCODILE_HIDE_BOOTS.setCustomArmorColor(crocodileArmorModel.value());

registerCustomModelItem(WOLF_HEAD, "wolf_head");
registerCustomModelItem(WOLF_SUIT_CHESTPLATE, "wolf_suit_chestplate");
registerCustomModelItem(WOLF_SUIT_LEGGINGS, "wolf_suit_leggings");
registerCustomModelItem(WOLF_SUIT_BOOTS, "wolf_suit_boots");
{
PolymerModelData data = PolymerRPUtils.requestModel(WOLF_HEAD.getPolymerItem(new ItemStack(WOLF_HEAD, 1), null), id("item/wolf_head_angry"));
WOLF_HEAD.setAngryData(data.value());
}

PolymerArmorModel wolfArmorModel = PolymerRPUtils.requestArmor(id("wolf_suit"));
WOLF_SUIT_CHESTPLATE.setCustomArmorColor(wolfArmorModel.value());
WOLF_SUIT_LEGGINGS.setCustomArmorColor(wolfArmorModel.value());
WOLF_SUIT_BOOTS.setCustomArmorColor(wolfArmorModel.value());

//Entities
FabricDefaultAttributeRegistry.register(GUST, GustEntity.createGustAttributes());
FabricDefaultAttributeRegistry.register(CROCODILE, CrocodileEntity.createCrocodileAttributes());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.slimeist.server_mobs.items;

import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.slimeist.server_mobs.mixin.ArmorItemAccessor;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public class WolfHeadArmorItem extends CustomArmorItem {
private int angryData = -1;
private final Multimap<EntityAttribute, EntityAttributeModifier> angryAttributeModifiers;

public WolfHeadArmorItem(ArmorItem armorItem, Item visualItem, ArmorMaterial material, Settings settings) {
super(armorItem, visualItem, material, settings);

Multimap<EntityAttribute, EntityAttributeModifier> superModifiers = super.getAttributeModifiers(super.getSlotType());
ImmutableMultimap.Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder();
builder.putAll(superModifiers);

UUID uUID = ArmorItemAccessor.getMODIFIERS()[slot.getEntitySlotId()];
builder.put(EntityAttributes.GENERIC_ATTACK_DAMAGE, new EntityAttributeModifier(uUID, "Wolf Head attack damage", 2.0D, EntityAttributeModifier.Operation.ADDITION));

angryAttributeModifiers = builder.build();
}

public void setAngryData(int angryData) {
this.angryData = angryData;
}

private void setAngry(ItemStack stack, boolean angry) {
if (angry) {
stack.getOrCreateNbt().putBoolean("Angry", true);
} else {
stack.removeSubNbt("Angry");
}
}

private boolean isAngry(ItemStack stack) {
return stack.getOrCreateNbt().getBoolean("Angry");
}

@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, selected);

if (entity instanceof ServerPlayerEntity serverPlayer) {
boolean shouldBeAngry = serverPlayer.getAttacker() != null || (serverPlayer.getAttacking() != null && serverPlayer.getLastAttackTime()-serverPlayer.age < 200);
boolean isAngry = isAngry(stack);
if (shouldBeAngry != isAngry) {
setAngry(stack, shouldBeAngry);

if (shouldBeAngry) {
serverPlayer.world.playSound(
null, serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(),
SoundEvents.ENTITY_WOLF_HOWL, SoundCategory.PLAYERS, 1.0f, 1.0f
);
} else {
serverPlayer.world.playSound(
null, serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(),
SoundEvents.ENTITY_WOLF_WHINE, SoundCategory.PLAYERS, 0.5f, 1.0f
);
}
}
}
}

@Override
public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) {
if (isAngry(itemStack)) {
return angryData;
}
return super.getPolymerCustomModelData(itemStack, player);
}

@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(ItemStack stack, EquipmentSlot slot) {
if (isAngry(stack) && slot == getSlotType())
return angryAttributeModifiers;
return super.getAttributeModifiers(stack, slot);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.slimeist.server_mobs.mixin;

import net.minecraft.item.ArmorItem;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.UUID;

@Mixin(ArmorItem.class)
public interface ArmorItemAccessor {
@Accessor("MODIFIERS")
static UUID[] getMODIFIERS() {
throw new AssertionError("Should have been mixed in");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#moj_import <fog.glsl>
#moj_import <emissive_utils.glsl>

#define IS_CUSTOM_EMISSIVE is_emissive(Sampler0) // If texture should have emissive

uniform sampler2D Sampler0;

uniform vec4 ColorModulator;
Expand All @@ -23,24 +21,12 @@ out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0);
if (is_emissive(Sampler0)) {
vec4 textureProperties = get_texture_properties(Sampler0);
vec4 lmc = get_light(textureProperties, color, lightMapColor);
color.a = get_alpha(textureProperties, color);

if (color.a < 0.1) {
discard;
}
color *= vertexColor * ColorModulator;
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
color *= lmc;
} else {
if (color.a < 0.1) {
discard;
}
color *= vertexColor * ColorModulator;
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
color *= lightMapColor;
if (color.a < 0.1) {
discard;
}
color *= vertexColor * ColorModulator;
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
float alpha = textureLod(Sampler0, texCoord0, 0.0).a;
color = make_emissive(color, lightMapColor, alpha);
fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0);

vec4 vtc = vertexColor;

if (is_emissive(Sampler0)) {
vec4 textureProperties = get_texture_properties(Sampler0);
vtc = get_light(textureProperties, color, vertexColor);
color.a = get_alpha(textureProperties, color);
}

color *= vtc * ColorModulator;
vec4 lightColor = vertexColor * ColorModulator;
float alpha = textureLod(Sampler0, texCoord0, 0.0).a;
color = make_emissive(color, lightColor, alpha);
if (color.a < 0.1) {
discard;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ out vec4 fragColor;

void main() {
vec4 color = texture(Sampler0, texCoord0);

vec4 vtc = vertexColor;

if (is_emissive(Sampler0)) {
vec4 textureProperties = get_texture_properties(Sampler0);
vtc = get_light(textureProperties, color, vertexColor);
color.a = get_alpha(textureProperties, color);
}

color *= vtc * ColorModulator;
vec4 lightColor = vertexColor * ColorModulator;
float alpha = textureLod(Sampler0, texCoord0, 0.0).a;
color = make_emissive(color, lightColor, alpha);
if (color.a < 0.1) {
discard;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,24 @@
#version 150

/*
Format:
(x, y): DESC (r, g, b, a)
---------------------------------
(0, 1): Marker pixel (1, 0, 1, 1)
(1, 1): textureProperties (e, a, b, c)
if e == 1:
pixels with the same alpha value as textureProperties become emissive with brightness b and alpha a
if e > 1:
everything is AWESOME err.. emissive with brightness b
*/

bool check_alpha(float textureAlpha, float targetAlpha) {
float targetLess = targetAlpha - 0.01;
float targetMore = targetAlpha + 0.01;
return (textureAlpha > targetLess && textureAlpha < targetMore);
}

bool is_emissive(sampler2D tex) {
return texelFetch(tex, ivec2(0, 1), 0) == vec4(1, 0, 1, 1);
}
// Makes sure transparent things don't become solid and vice versa.
float remap_alpha(float inputAlpha) {

vec4 get_texture_properties(sampler2D tex) {
return texelFetch(tex, ivec2(1, 1), 0) * 255;
}
if (check_alpha(inputAlpha, 250.0/255.0)) return 1.0; // Crocodile & Wolf eyes

vec4 get_light(vec4 textureProperties, vec4 tex_color, vec4 original) {
if (textureProperties.r == 1) {
if (check_alpha(tex_color.a*255, textureProperties.a))
{
return vec4(textureProperties.b/255);
}
} else if (textureProperties.r > 1) {
return vec4(textureProperties.b/255);
}
return original;
return float(inputAlpha); // If a pixel doesn't need to have its alpha changed then it simply does not change.
}

float get_alpha(vec4 textureProperties, vec4 tex_color) {
if (textureProperties.r == 1) {
if (check_alpha(tex_color.a*255, textureProperties.a))
{
return textureProperties.g/255;
}
}
return tex_color.a;

vec4 make_emissive(vec4 inputColor, vec4 lightColor, float inputAlpha) {
inputColor.a = remap_alpha(inputAlpha); // Remap the alpha value

if (check_alpha(inputAlpha, 250.0/255.0)) return inputColor;

return inputColor * lightColor; // If none of the pixels are supposed to be emissive, then it adds the light.
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 4 additions & 0 deletions src/main/resources/assets/server_mobs/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"item.server_mobs.crocodile_hide_boots": "Crocodile Hide Boots",
"item.server_mobs.crocodile_hide": "Crocodile Hide",
"item.server_mobs.crocodile_tooth": "Crocodile Tooth",
"item.server_mobs.wolf_head": "Wolf Head",
"item.server_mobs.wolf_suit_chestplate": "Wolf Suit Chestplate",
"item.server_mobs.wolf_suit_leggings": "Wolf Suit Leggings",
"item.server_mobs.wolf_suit_boots": "Wolf Suit Boots",

"block.server_mobs.crocodile_flute": "Crocodile Flute",

Expand Down
Loading

0 comments on commit 12687b2

Please sign in to comment.