Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
feat: WIP for capturing mobs in jars
Browse files Browse the repository at this point in the history
  • Loading branch information
chimericdream committed Oct 1, 2024
1 parent 20ded72 commit 4651332
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.fabricmc.fabric.api.object.builder.v1.block.entity.FabricBlockEntityTypeBuilder;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;
import net.minecraft.data.client.BlockStateModelGenerator;
import net.minecraft.data.client.ItemModelGenerator;
import net.minecraft.data.server.loottable.BlockLootTableGenerator;
Expand Down Expand Up @@ -58,7 +57,7 @@ public void initializeClient() {

BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(), GLASS_JAR);

BlockEntityRendererRegistry.register(GLASS_JAR_BLOCK_ENTITY, GlassJarBlockEntityRenderer::new);
BlockEntityRendererFactories.register(GLASS_JAR_BLOCK_ENTITY, GlassJarBlockEntityRenderer::new);
}

@Override
Expand All @@ -77,7 +76,7 @@ public void registerBlockEntities() {
GLASS_JAR_BLOCK_ENTITY = Registry.register(
Registries.BLOCK_ENTITY_TYPE,
GlassJarBlockEntity.ENTITY_ID,
FabricBlockEntityTypeBuilder.create(GlassJarBlockEntity::new, GLASS_JAR).build(null)
BlockEntityType.Builder.create(GlassJarBlockEntity::new, GLASS_JAR).build(null)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.texture.Sprite;
Expand All @@ -38,7 +39,8 @@ public class GlassJarBlockEntityRenderer implements BlockEntityRenderer<GlassJar
// Ensures that the total height of the contents doesn't go above the top
private static final float VERTICAL_MULTIPLIER = 9f / 16f;

private final ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
private final ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
private final EntityRenderDispatcher entityRenderer = MinecraftClient.getInstance().getEntityRenderDispatcher();

public GlassJarBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {
}
Expand Down Expand Up @@ -283,7 +285,7 @@ private void renderItem(GlassJarBlockEntity entity, MatrixStack matrices, Vertex
matrices.scale(0.749f, fY, 0.749f);

int lightAbove = world == null ? 15728880 : WorldRenderer.getLightmapCoordinates(world, pos.up());
renderer.renderItem(stack, ModelTransformationMode.FIXED, lightAbove, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, null, 0);
itemRenderer.renderItem(stack, ModelTransformationMode.FIXED, lightAbove, OverlayTexture.DEFAULT_UV, matrices, vertexConsumers, null, 0);

matrices.pop();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
package com.chimericdream.minekea.item.containers;

import net.minecraft.block.Block;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;

public class GlassJarItem extends BlockItem {
public GlassJarItem(Block block, Settings settings) {
super(block, settings);
}

@Override
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) {
NbtCompound data = stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).copyNbt();

if (data.isEmpty()) {
entity.writeNbt(data);
// if the stack has more than one, remove one to separate stack
// write the custom data to the stack
// remove the entity from the world
}

return ActionResult.PASS;
}
}

0 comments on commit 4651332

Please sign in to comment.