Skip to content

Commit

Permalink
Complete the maid spawn design
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Oct 9, 2021
1 parent 62a2b19 commit b64e86c
Show file tree
Hide file tree
Showing 22 changed files with 385 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void spawnResultEntity(World world, PlayerEntity playerIn, PowerCapabili
power.min(altarRecipe.getPowerCost());
BlockPos centrePos = getCentrePos(altar.getBlockPosList(), altar.getBlockPos());
if (world instanceof ServerWorld) {
altarRecipe.spawnOutputEntity((ServerWorld) world, centrePos, inventory);
altarRecipe.spawnOutputEntity((ServerWorld) world, centrePos.above(2), inventory);
}
removeAllAltarItem(world, altar);
spawnParticleInCentre(world, centrePos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.tartaricacid.touhoulittlemaid.client.renderer.entity.*;
import com.github.tartaricacid.touhoulittlemaid.client.renderer.tileentity.TileEntityAltarRenderer;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityBox;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityExtinguishingAgent;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityPowerPoint;
Expand All @@ -26,6 +27,7 @@ public static void clientSetup(FMLClientSetupEvent evt) {
RenderingRegistry.registerEntityRenderingHandler(EntityDanmaku.TYPE, EntityDanmakuRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(EntityPowerPoint.TYPE, EntityPowerPointRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(EntityExtinguishingAgent.TYPE, EntityExtinguishingAgentRenderer::new);
RenderingRegistry.registerEntityRenderingHandler(EntityBox.TYPE, EntityBoxRender::new);
ClientRegistry.bindTileEntityRenderer(TileEntityAltar.TYPE, TileEntityAltarRenderer::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.github.tartaricacid.touhoulittlemaid.client.model;

import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityBox;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;

public class EntityBoxModel extends EntityModel<EntityBox> {
private final ModelRenderer bottom;
private final ModelRenderer x1;
private final ModelRenderer x2;
private final ModelRenderer z1;
private final ModelRenderer z2;
private final ModelRenderer top;

public EntityBoxModel() {
texWidth = 256;
texHeight = 256;

bottom = new ModelRenderer(this);
bottom.setPos(0.0F, 24.0F, 0.0F);
bottom.texOffs(0, 0).addBox(-15.0F, -1.0F, -15.0F, 30.0F, 1.0F, 30.0F, 0.0F, false);

x1 = new ModelRenderer(this);
x1.setPos(0.0F, 23.5F, -14.5F);
x1.texOffs(64, 31).addBox(-14.0F, -30.5F, -0.5F, 28.0F, 30.0F, 1.0F, 0.0F, false);

x2 = new ModelRenderer(this);
x2.setPos(0.0F, 23.5F, 14.5F);
x2.texOffs(64, 31).addBox(-14.0F, -30.5F, -0.5F, 28.0F, 30.0F, 1.0F, 0.0F, false);

z1 = new ModelRenderer(this);
z1.setPos(14.5F, 23.5F, 0.0F);
z1.texOffs(0, 31).addBox(-0.5F, -30.5F, -15.0F, 1.0F, 30.0F, 30.0F, 0.0F, false);

z2 = new ModelRenderer(this);
z2.setPos(-14.5F, 23.5F, 0.0F);
z2.texOffs(0, 31).addBox(-0.5F, -30.5F, -15.0F, 1.0F, 30.0F, 30.0F, 0.0F, false);

top = new ModelRenderer(this);
top.setPos(0.0F, 24.0F, 0.0F);
top.texOffs(0, 0).addBox(-15.0F, -32.0F, -15.0F, 30.0F, 1.0F, 30.0F, 0.0F, false);
top.texOffs(64, 64).addBox(-16.0F, -32.0F, -16.0F, 32.0F, 6.0F, 1.0F, 0.0F, false);
top.texOffs(64, 64).addBox(-16.0F, -32.0F, 15.0F, 32.0F, 6.0F, 1.0F, 0.0F, false);
top.texOffs(32, 61).addBox(-16.0F, -32.0F, -15.0F, 1.0F, 6.0F, 30.0F, 0.0F, false);
top.texOffs(32, 61).addBox(15.0F, -32.0F, -15.0F, 1.0F, 6.0F, 30.0F, 0.0F, false);
}

@Override
public void setupAnim(EntityBox entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
int stage = entityIn.getOpenStage();
if (stage == EntityBox.FIRST_STAGE) {
top.visible = true;
x1.xRot = 0;
x2.xRot = 0;
z1.zRot = 0;
z2.zRot = 0;
} else if (stage > EntityBox.SECOND_STAGE) {
top.visible = false;
x1.xRot = 0;
x2.xRot = 0;
z1.zRot = 0;
z2.zRot = 0;
} else {
top.visible = false;
x1.xRot = 0.023998277f * (EntityBox.SECOND_STAGE - stage);
x2.xRot = -0.023998277f * (EntityBox.SECOND_STAGE - stage);
z1.zRot = 0.023998277f * (EntityBox.SECOND_STAGE - stage);
z2.zRot = -0.023998277f * (EntityBox.SECOND_STAGE - stage);
}
}

@Override
public void renderToBuffer(MatrixStack matrixStack, IVertexBuilder buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
bottom.render(matrixStack, buffer, packedLight, packedOverlay);
x1.render(matrixStack, buffer, packedLight, packedOverlay);
x2.render(matrixStack, buffer, packedLight, packedOverlay);
z1.render(matrixStack, buffer, packedLight, packedOverlay);
z2.render(matrixStack, buffer, packedLight, packedOverlay);
top.render(matrixStack, buffer, packedLight, packedOverlay);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.tartaricacid.touhoulittlemaid.client.renderer.entity;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.client.model.EntityBoxModel;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityBox;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.ResourceLocation;

import java.util.List;
import java.util.stream.IntStream;

public class EntityBoxRender extends EntityRenderer<EntityBox> {
private final List<ResourceLocation> texturesGroup = Lists.newArrayList();
private final EntityModel<EntityBox> boxModel;

public EntityBoxRender(EntityRendererManager manager) {
super(manager);
boxModel = new EntityBoxModel();
IntStream.range(0, EntityBox.MAX_TEXTURE_SIZE).forEach(this::addBoxTexture);
}

@Override
public void render(EntityBox entityBox, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer bufferIn, int packedLight) {
matrixStack.pushPose();
matrixStack.scale(-1.0F, -1.0F, 1.0F);
matrixStack.translate(0.0, -1.501, 0.0);
boxModel.setupAnim(entityBox, 0, 0, -0.1f, 0, 0);
RenderType renderType = RenderType.entityTranslucent(getTextureLocation(entityBox));
IVertexBuilder buffer = bufferIn.getBuffer(renderType);
boxModel.renderToBuffer(matrixStack, buffer, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
matrixStack.popPose();
}

@Override
public ResourceLocation getTextureLocation(EntityBox entity) {
return texturesGroup.get(entity.getTextureIndex());
}

private void addBoxTexture(int index) {
String fileName = String.format("textures/entity/box/cake_box_%s.png", index);
texturesGroup.add(new ResourceLocation(TouhouLittleMaid.MOD_ID, fileName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import com.github.tartaricacid.touhoulittlemaid.init.InitRecipes;
import com.github.tartaricacid.touhoulittlemaid.inventory.AltarRecipeInventory;
import com.google.common.base.Preconditions;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
Expand All @@ -15,12 +17,12 @@
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.RecipeMatcher;

import javax.annotation.Nullable;
import java.util.Objects;

import static com.github.tartaricacid.touhoulittlemaid.inventory.AltarRecipeInventory.RECIPES_SIZE;

Expand All @@ -40,7 +42,7 @@ public AltarRecipe(ResourceLocation id, EntityType<?> entityType, @Nullable Comp
this.entityType = entityType;
this.isItemCraft = (entityType == EntityType.ITEM);
if (this.isItemCraft && extraData != null) {
this.resultItem = ItemStack.of(extraData.getCompound("EntityTag").getCompound("Item"));
this.resultItem = ItemStack.of(extraData.getCompound("Item"));
} else {
this.resultItem = ItemStack.EMPTY;
}
Expand Down Expand Up @@ -113,10 +115,30 @@ public float getPowerCost() {
}

public void spawnOutputEntity(ServerWorld world, BlockPos pos, AltarRecipeInventory inventory) {
entityType.spawn(world, extraData, StringTextComponent.EMPTY, null, pos, SpawnReason.SPAWN_EGG, true, true);
if (extraData != null) {
CompoundNBT nbt = this.extraData.copy();
nbt.putString("id", Objects.requireNonNull(entityType.getRegistryName()).toString());
Entity resultEntity = EntityType.loadEntityRecursive(nbt, world, (e) -> {
e.moveTo(pos.getX(), pos.getY(), pos.getZ(), e.yRot, e.xRot);
this.finalizeSpawn(world, pos, e);
return e;
});
if (resultEntity != null) {
this.finalizeSpawn(world, pos, resultEntity);
world.tryAddFreshEntityWithPassengers(resultEntity);
}
return;
}
entityType.spawn(world, null, null, null, pos, SpawnReason.SPAWN_EGG, true, true);
}

public boolean isItemCraft() {
return isItemCraft;
}

private void finalizeSpawn(ServerWorld world, BlockPos pos, @Nullable Entity entity) {
if (entity instanceof MobEntity) {
((MobEntity) entity).finalizeSpawn(world, world.getCurrentDifficultyAt(pos), SpawnReason.SPAWN_EGG, null, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.Tags;
Expand All @@ -26,6 +27,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

import static com.github.tartaricacid.touhoulittlemaid.init.InitItems.*;

Expand Down Expand Up @@ -70,7 +72,15 @@ protected void registerRecipes() {
Ingredient coal = Ingredient.of(Items.COAL);
Ingredient netherWart = Ingredient.of(Items.NETHER_WART);

addEntityRecipes(InitEntities.MAID.get(), 0.5f, gemDiamond, gemLapis, ingotGold, redstone, ingotIron, coal);
{
CompoundNBT extraData = new CompoundNBT();
ListNBT passengerList = new ListNBT();
CompoundNBT passenger = new CompoundNBT();
passenger.putString("id", Objects.requireNonNull(InitEntities.MAID.get().getRegistryName()).toString());
passengerList.add(passenger);
extraData.put("Passengers", passengerList);
addEntityRecipes(InitEntities.BOX.get(), extraData, 0.5f, gemDiamond, gemLapis, ingotGold, redstone, ingotIron, coal);
}
addEntityRecipes(EntityType.LIGHTNING_BOLT, 0.2f, gunpowder, gunpowder, gunpowder, blazePowder, blazePowder, blazePowder);
addItemRecipes(HAKUREI_GOHEI, 0.15f, stick, stick, stick, paper, paper, paper);
addItemRecipes(ULTRAMARINE_ORB_ELIXIR, 0.3f, gemEmerald, enderPearl, dyeCyan, dyeCyan, dyeCyan, dyeCyan);
Expand Down
Loading

0 comments on commit b64e86c

Please sign in to comment.