Skip to content

Commit

Permalink
Merge pull request #4 from Lithewings/7-15-5
Browse files Browse the repository at this point in the history
7 15 5
  • Loading branch information
Lithewings authored Jul 15, 2024
2 parents 1484663 + b7b5468 commit 10b46e1
Show file tree
Hide file tree
Showing 41 changed files with 1,157 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/equilibrium/MITEequilibrium.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import com.equilibrium.block.ModBlocks;

import com.equilibrium.entity.ModEntities;
import com.equilibrium.entity.mob.TestZombieEntity;
import com.equilibrium.item.Ingots;
import com.equilibrium.item.ModItemGroup;
import com.equilibrium.item.ModItems;
import com.equilibrium.item.Tools;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.equilibrium.entity.ModEntities.TEST_ZOMBIE;
import static com.equilibrium.entity.ModEntities.registerModEntities;
import static com.equilibrium.worldgen.ModOreGenerator.registerModOre;


Expand Down Expand Up @@ -47,7 +53,7 @@ public void onInitialize() {




registerModEntities();



Expand All @@ -56,4 +62,5 @@ public void onInitialize() {

LOGGER.info("Hello Fabric world!");
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/equilibrium/MITEequilibriumClient.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
package com.equilibrium;


import com.equilibrium.client.render.entity.InvisibleStalker;
import com.equilibrium.client.render.entity.TestZombie;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;

import static com.equilibrium.entity.ModEntities.INVISIBLE_STALKER;
import static com.equilibrium.entity.ModEntities.TEST_ZOMBIE;


public class MITEequilibriumClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
//将注册的实体和模型结合起来


EntityRendererRegistry.register(TEST_ZOMBIE, TestZombie::new);
EntityRendererRegistry.register(INVISIBLE_STALKER, InvisibleStalker::new);







}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.equilibrium.client.render.entity;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.entity.BipedEntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer;
import net.minecraft.client.render.entity.model.ZombieEntityModel;
import net.minecraft.entity.mob.ZombieEntity;

@Environment(EnvType.CLIENT)
public abstract class AbstractZombieEntityRenderer<T extends ZombieEntity, M extends ZombieEntityModel<T>> extends BipedEntityRenderer<T, M> {


protected AbstractZombieEntityRenderer(EntityRendererFactory.Context ctx, M bodyModel, M legsArmorModel, M bodyArmorModel) {
super(ctx, bodyModel, 0.5F);
this.addFeature(new ArmorFeatureRenderer<>(this, legsArmorModel, bodyArmorModel, ctx.getModelManager()));
}


protected boolean isShaking(T zombieEntity) {
return super.isShaking(zombieEntity) || zombieEntity.isConvertingInWater();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.equilibrium.client.render.entity;

import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.client.render.entity.model.ZombieEntityModel;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.util.Identifier;

public class InvisibleStalker extends AbstractZombieEntityRenderer<ZombieEntity, ZombieEntityModel<ZombieEntity>> {
private static final Identifier TEXTURE = Identifier.of("miteequilibrium","textures/entity/invisible_stalker.png");

public Identifier getTexture(ZombieEntity zombieEntity) {
return TEXTURE;
}

public InvisibleStalker(EntityRendererFactory.Context context) {
this(context, EntityModelLayers.ZOMBIE, EntityModelLayers.ZOMBIE_INNER_ARMOR, EntityModelLayers.ZOMBIE_OUTER_ARMOR);
}

public InvisibleStalker(EntityRendererFactory.Context ctx, EntityModelLayer layer, EntityModelLayer legsArmorLayer, EntityModelLayer bodyArmorLayer) {
super(
ctx, new ZombieEntityModel<>(ctx.getPart(layer)), new ZombieEntityModel<>(ctx.getPart(legsArmorLayer)), new ZombieEntityModel<>(ctx.getPart(bodyArmorLayer))
);

}





}

30 changes: 30 additions & 0 deletions src/main/java/com/equilibrium/client/render/entity/TestZombie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.equilibrium.client.render.entity;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.client.render.entity.model.ZombieEntityModel;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class TestZombie extends AbstractZombieEntityRenderer<ZombieEntity, ZombieEntityModel<ZombieEntity>> {


private static final Identifier TEXTURE = Identifier.ofVanilla("textures/entity/player/wide/steve.png");
public Identifier getTexture(ZombieEntity zombieEntity) {
return TEXTURE;
}
public TestZombie(EntityRendererFactory.Context context) {
this(context, EntityModelLayers.ZOMBIE, EntityModelLayers.ZOMBIE_INNER_ARMOR, EntityModelLayers.ZOMBIE_OUTER_ARMOR);

}
public TestZombie(EntityRendererFactory.Context ctx, EntityModelLayer layer, EntityModelLayer legsArmorLayer, EntityModelLayer bodyArmorLayer) {
super(
ctx, new ZombieEntityModel<>(ctx.getPart(layer)), new ZombieEntityModel<>(ctx.getPart(legsArmorLayer)), new ZombieEntityModel<>(ctx.getPart(bodyArmorLayer))
);
}

}
45 changes: 45 additions & 0 deletions src/main/java/com/equilibrium/entity/ModEntities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.equilibrium.entity;

import com.equilibrium.entity.mob.TestZombieEntity;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityType;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

import java.util.function.UnaryOperator;


public class ModEntities {
//注册实体
public static final EntityType<TestZombieEntity> TEST_ZOMBIE = Registry.register(Registries.ENTITY_TYPE,
Identifier.of("miteequilibrium","test_zombie"),
//fixed(width, height)
FabricEntityTypeBuilder.create(SpawnGroup.MONSTER,TestZombieEntity::new).dimensions(EntityDimensions.fixed(0.75f, 1.95f)).build());


public static final EntityType<TestZombieEntity> INVISIBLE_STALKER = Registry.register(Registries.ENTITY_TYPE,
Identifier.of("miteequilibrium","invisible_stalker"),
//fixed(width, height)
FabricEntityTypeBuilder.create(SpawnGroup.MONSTER,TestZombieEntity::new).dimensions(EntityDimensions.fixed(0.75f, 1.95f)).build());







//注册属性
public static void registerModEntities(){
FabricDefaultAttributeRegistry.register(TEST_ZOMBIE, TestZombieEntity.createZombieAttributes());
FabricDefaultAttributeRegistry.register(INVISIBLE_STALKER, TestZombieEntity.createZombieAttributes());


}

}
18 changes: 18 additions & 0 deletions src/main/java/com/equilibrium/entity/mob/TestZombieEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.equilibrium.entity.mob;

import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.model.AbstractZombieModel;
import net.minecraft.client.render.entity.model.EntityModelLayers;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.CaveSpiderEntity;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.world.World;

public class TestZombieEntity extends ZombieEntity {
public TestZombieEntity(EntityType<? extends TestZombieEntity> entityType, World world) {
super(entityType, world);
}

}


82 changes: 82 additions & 0 deletions src/main/java/com/equilibrium/mixin/HungerManagerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.equilibrium.mixin;

import com.equilibrium.util.PlayerMaxHungerHelper;
import net.minecraft.entity.player.HungerManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import static com.equilibrium.MITEequilibrium.LOGGER;

@Mixin(HungerManager.class)







public abstract class HungerManagerMixin {






//营养值没满,就能一直吃下去
@Inject(method = "isNotFull",at = @At(value = "HEAD"),cancellable = true)
public void isNotFull(CallbackInfoReturnable<Boolean> cir) {

int maxFoodLevel= PlayerMaxHungerHelper.getMaxFoodLevel();

cir.setReturnValue(this.saturationLevel < maxFoodLevel);

}

@Shadow
private int foodLevel;
@Shadow
private float saturationLevel;
@Shadow
private float exhaustion;
@Shadow
private int foodTickTimer;
@Shadow
private int prevFoodLevel ;

@Inject(method = "addInternal",at = @At("HEAD"), cancellable = true)
private void addInternal(int nutrition, float saturation, CallbackInfo ci) {
ci.cancel();
//获取饱食度上限
int maxFoodLevel = PlayerMaxHungerHelper.getMaxFoodLevel();
//即便饱食度已满,也可以继续吃东西,将饱食度加在饱和度上
LOGGER.info("The food attributes: "+nutrition+" "+saturation);

LOGGER.info("The foodLevel before: "+this.foodLevel);
LOGGER.info("The saturationLevel before: "+this.saturationLevel);

//先临时增加16倍的饱食度上限
this.foodLevel = MathHelper.clamp(nutrition + this.foodLevel, 0, 16*maxFoodLevel);
//若发生溢出
if(this.foodLevel>maxFoodLevel){
//获取溢出值
int overflowFoodLevel = foodLevel-maxFoodLevel;
LOGGER.info("overflowFoodLevel = "+overflowFoodLevel);
//加到饱和度上
this.saturationLevel = MathHelper.clamp(overflowFoodLevel + this.saturationLevel, 0.0F,maxFoodLevel);
//还原到溢出前的最大值
this.foodLevel=maxFoodLevel;
}
this.saturationLevel = MathHelper.clamp(saturation + this.saturationLevel, 0.0F, maxFoodLevel);


LOGGER.info("The foodLevel after: "+this.foodLevel);
LOGGER.info("The saturationLevel after: "+this.saturationLevel);
}
}
Loading

0 comments on commit 10b46e1

Please sign in to comment.