-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Lithewings/7-15-5
7 15 5
- Loading branch information
Showing
41 changed files
with
1,157 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/equilibrium/client/render/entity/AbstractZombieEntityRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/equilibrium/client/render/entity/InvisibleStalker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
src/main/java/com/equilibrium/client/render/entity/TestZombie.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/main/java/com/equilibrium/entity/mob/TestZombieEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
82
src/main/java/com/equilibrium/mixin/HungerManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.