Skip to content

Commit

Permalink
cookie jar funsies
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Mar 6, 2024
1 parent 554613d commit 0f109ea
Show file tree
Hide file tree
Showing 15 changed files with 204 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 1.20.4 2024-02-29T22:46:48.1741486 Tags for minecraft:item mod id bibliocraft
// 1.20.4 2024-03-06T15:27:13.5046437 Tags for minecraft:item mod id bibliocraft
dc932537352be3adc3e92269d526190a3da02a50 data/bibliocraft/tags/items/bookcases.json
8c21eecc9ff3212b039c2ccadcebce2ef5e04510 data/bibliocraft/tags/items/bookcase_books.json
a62188adba8d65fe5971b95f4c552a1072086c31 data/bibliocraft/tags/items/cookie_jar_cookies.json
89057f18fe8255a1a50953beaeaa02f75b41c2b9 data/bibliocraft/tags/items/display_cases.json
474090b2b5b40b58b63496e56ed06e543323d894 data/bibliocraft/tags/items/fancy_armor_stands.json
b46d2615e18035acc6efa4ddc52a0f55fea31342 data/bibliocraft/tags/items/fancy_armor_stands/wood.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:cookie"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.minecraftschurlimods.bibliocraft.Bibliocraft;
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftWoodType;
import com.github.minecraftschurlimods.bibliocraft.api.BibliocraftWoodTypeRegistry;
import com.github.minecraftschurlimods.bibliocraft.client.ber.CookieJarBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.DisplayCaseBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.FancyArmorStandBER;
import com.github.minecraftschurlimods.bibliocraft.client.ber.LabelBER;
Expand Down Expand Up @@ -40,6 +41,7 @@ public static final class ModBus {
@SubscribeEvent
private static void registerMenuScreens(RegisterMenuScreensEvent event) {
event.register(BCMenus.BOOKCASE.get(), BCMenuScreens.Bookcase::new);
event.register(BCMenus.COOKIE_JAR.get(), BCMenuScreens.CookieJar::new);
event.register(BCMenus.FANCY_ARMOR_STAND.get(), BCMenuScreens.FancyArmorStand::new);
event.register(BCMenus.LABEL.get(), BCMenuScreens.Label::new);
event.register(BCMenus.POTION_SHELF.get(), BCMenuScreens.PotionShelf::new);
Expand Down Expand Up @@ -71,6 +73,7 @@ private static void registerGeometryLoaders(ModelEvent.RegisterGeometryLoaders e
private static void registerRenderers(EntityRenderersEvent.RegisterRenderers event) {
event.registerEntityRenderer(BCEntities.FANCY_ARMOR_STAND.get(), ArmorStandRenderer::new);
event.registerEntityRenderer(BCEntities.SEAT.get(), EmptyEntityRenderer::new);
event.registerBlockEntityRenderer(BCBlockEntities.COOKIE_JAR.get(), CookieJarBER::new);
event.registerBlockEntityRenderer(BCBlockEntities.DISPLAY_CASE.get(), DisplayCaseBER::new);
event.registerBlockEntityRenderer(BCBlockEntities.FANCY_ARMOR_STAND.get(), FancyArmorStandBER::new);
event.registerBlockEntityRenderer(BCBlockEntities.LABEL.get(), LabelBER::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.github.minecraftschurlimods.bibliocraft.client.ber;

import com.github.minecraftschurlimods.bibliocraft.content.cookiejar.CookieJarBlockEntity;
import com.github.minecraftschurlimods.bibliocraft.init.BCTags;
import com.github.minecraftschurlimods.bibliocraft.util.ClientUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.levelgen.LegacyRandomSource;

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

public class CookieJarBER implements BlockEntityRenderer<CookieJarBlockEntity> {
private final RandomSource random = new LegacyRandomSource(0);

@SuppressWarnings("unused")
public CookieJarBER(BlockEntityRendererProvider.Context context) {
}

@Override
public void render(CookieJarBlockEntity blockEntity, float partialTick, PoseStack stack, MultiBufferSource buffer, int light, int overlay) {
List<ItemStack> items = IntStream.rangeClosed(0, blockEntity.getContainerSize() - 1)
.mapToObj(blockEntity::getItem)
.filter(e -> !e.isEmpty())
.toList();
List<ItemStack> cookies = BuiltInRegistries.ITEM.getTag(BCTags.Items.COOKIE_JAR_COOKIES)
.orElseThrow()
.stream()
.sorted(Comparator.comparing(a -> BuiltInRegistries.ITEM.getKey(a.value())))
.map(ItemStack::new)
.toList();
random.setSeed(blockEntity.getBlockPos().asLong());
stack.translate(0.5, 0.5, 0.5);
for (int i = 0; i < items.size(); i++) {
ItemStack item = items.get(i);
ItemStack cookie = cookies.get(random.nextInt(cookies.size()));
stack.pushPose();
cookiePosition(i, stack);
ClientUtil.renderFixedItem(item.is(BCTags.Items.COOKIE_JAR_COOKIES) ? item : cookie, stack, buffer, light, overlay);
stack.popPose();
}
}

private void cookiePosition(int index, PoseStack stack) {
switch (index) {
case 0:
stack.translate(-0.1, -0.425, 0.1);
break;
case 1:
stack.translate(-0.0875, -0.3875, -0.0875);
stack.mulPose(Axis.XP.rotationDegrees(-15));
break;
case 2:
stack.translate(0.1, -0.3325, 0);
stack.mulPose(Axis.ZP.rotationDegrees(-20));
break;
case 3:
stack.translate(0.1, -0.295, -0.125);
stack.mulPose(Axis.XP.rotationDegrees(-15));
stack.mulPose(Axis.ZP.rotationDegrees(-15));
break;
case 4:
stack.translate(-0.1, -0.245, 0.15);
stack.mulPose(Axis.XP.rotationDegrees(35));
stack.mulPose(Axis.YP.rotationDegrees(180));
break;
case 5:
stack.translate(-0.1, -0.1625, -0.125);
stack.mulPose(Axis.XP.rotationDegrees(-30));
stack.mulPose(Axis.ZP.rotationDegrees(5));
break;
case 6:
stack.translate(-0.1, -0.1325, 0.1575);
stack.mulPose(Axis.XP.rotationDegrees(45));
stack.mulPose(Axis.ZP.rotationDegrees(10));
stack.mulPose(Axis.YP.rotationDegrees(180));
break;
case 7:
stack.translate(0.2, -0.125, 0.1);
stack.mulPose(Axis.XP.rotationDegrees(30));
stack.mulPose(Axis.ZP.rotationDegrees(-60));
stack.mulPose(Axis.YP.rotationDegrees(-105));
break;
}
stack.mulPose(Axis.XP.rotationDegrees(90));
stack.scale(0.6f, 0.6f, 0.6f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.minecraftschurlimods.bibliocraft.Bibliocraft;
import com.github.minecraftschurlimods.bibliocraft.content.bookcase.BookcaseMenu;
import com.github.minecraftschurlimods.bibliocraft.content.cookiejar.CookieJarMenu;
import com.github.minecraftschurlimods.bibliocraft.content.fancyarmorstand.FancyArmorStandMenu;
import com.github.minecraftschurlimods.bibliocraft.content.label.LabelMenu;
import com.github.minecraftschurlimods.bibliocraft.content.potionshelf.PotionShelfMenu;
Expand All @@ -20,6 +21,14 @@ public Bookcase(BookcaseMenu menu, Inventory inventory, Component title) {
}
}

public static class CookieJar extends BCMenuScreen<CookieJarMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(Bibliocraft.MOD_ID, "textures/gui/cookie_jar.png");

public CookieJar(CookieJarMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title, BACKGROUND);
}
}

public static class FancyArmorStand extends BCMenuScreen<FancyArmorStandMenu> {
private static final ResourceLocation BACKGROUND = new ResourceLocation(Bibliocraft.MOD_ID, "textures/gui/fancy_armor_stand.png");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public CookieJarMenu(int id, Inventory inventory, FriendlyByteBuf buf) {

@Override
protected void addSlots(Inventory inventory) {

for (int j = 0; j < 4; j++) {
addSlot(new BCSlot(blockEntity, j, j * 32 + 32, 22));
addSlot(new BCSlot(blockEntity, j + 4, j * 32 + 32, 51));
}
addInventorySlots(inventory, 8, 84);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected void addTags(HolderLookup.Provider lookupProvider) {
tag(BCTags.Items.FANCY_ARMOR_STANDS).addTag(BCTags.Items.FANCY_ARMOR_STANDS_WOOD).add(BCItems.IRON_FANCY_ARMOR_STAND.get());
tag(BCTags.Items.SEAT_BACKS).addTags(BCTags.Items.SEAT_BACKS_SMALL, BCTags.Items.SEAT_BACKS_RAISED, BCTags.Items.SEAT_BACKS_FLAT, BCTags.Items.SEAT_BACKS_TALL, BCTags.Items.SEAT_BACKS_FANCY);
tag(BCTags.Items.BOOKCASE_BOOKS).addTags(ItemTags.BOOKSHELF_BOOKS, ItemTags.LECTERN_BOOKS).add(BCItems.REDSTONE_BOOK.get()).addOptional(new ResourceLocation("patchouli", "guide_book"));
tag(BCTags.Items.COOKIE_JAR_COOKIES).add(Items.COOKIE);
tag(BCTags.Items.POTION_SHELF_POTIONS).add(Items.POTION, Items.SPLASH_POTION, Items.LINGERING_POTION, Items.GLASS_BOTTLE, Items.EXPERIENCE_BOTTLE, Items.HONEY_BOTTLE, Items.DRAGON_BREATH);
tag(BCTags.Items.SWORD_PEDESTAL_SWORDS).addTag(ItemTags.SWORDS);
tag(BCTags.Items.TOOL_RACK_TOOLS).addTag(Tags.Items.TOOLS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface Items {
TagKey<Item> TABLES = tag("tables");
TagKey<Item> TOOL_RACKS = tag("tool_racks");
TagKey<Item> BOOKCASE_BOOKS = tag("bookcase_books");
TagKey<Item> COOKIE_JAR_COOKIES = tag("cookie_jar_cookies");
TagKey<Item> POTION_SHELF_POTIONS = tag("potion_shelf_potions");
TagKey<Item> SWORD_PEDESTAL_SWORDS = tag("sword_pedestal_swords");
TagKey<Item> TOOL_RACK_TOOLS = tag("tool_rack_tools");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,38 +1,73 @@
package com.github.minecraftschurlimods.bibliocraft.util.content;

import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;

/**
* Abstract superclass for non-rotatable entity blocks in this mod.
*/
@SuppressWarnings({"deprecation", "DuplicatedCode"})
public abstract class BCEntityBlock extends BCWaterloggedBlock implements BCBaseEntityBlock {
public abstract class BCEntityBlock extends BCWaterloggedBlock implements EntityBlock {
public BCEntityBlock(Properties properties) {
super(properties);
}

@Override
public PushReaction getPistonPushReaction(BlockState state) {
return PushReaction.BLOCK;
}

@Override
public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) {
BCBaseEntityBlock.super.setPlacedBy(level, pos, state, entity, stack, () -> super.setPlacedBy(level, pos, state, entity, stack));
super.setPlacedBy(level, pos, state, entity, stack);
if (level.getBlockEntity(pos) instanceof BCMenuBlockEntity blockEntity && stack.hasCustomHoverName()) {
blockEntity.setCustomName(stack.getHoverName());
}
}

@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean flag) {
BCBaseEntityBlock.super.onRemove(state, level, pos, newState, flag, this, () -> super.onRemove(state, level, pos, newState, flag));
if (!state.is(newState.getBlock())) {
BlockEntity blockentity = level.getBlockEntity(pos);
if (blockentity instanceof Container container) {
Containers.dropContents(level, pos, container);
level.updateNeighbourForOutputSignal(pos, this);
}
super.onRemove(state, level, pos, newState, flag);
}
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
return player.isSecondaryUseActive() ? InteractionResult.PASS : BCUtil.openBEMenu(player, level, pos);
}

@Override
public boolean triggerEvent(BlockState state, Level level, BlockPos pos, int id, int param) {
return BCBaseEntityBlock.super.triggerEvent(state, level, pos, id, param, () -> super.triggerEvent(state, level, pos, id, param));
super.triggerEvent(state, level, pos, id, param);
BlockEntity blockentity = level.getBlockEntity(pos);
return blockentity != null && blockentity.triggerEvent(id, param);
}

@Nullable
@Override
public MenuProvider getMenuProvider(BlockState state, Level level, BlockPos pos) {
BlockEntity blockentity = level.getBlockEntity(pos);
return blockentity instanceof MenuProvider ? (MenuProvider) blockentity : null;
}
}
Loading

0 comments on commit 0f109ea

Please sign in to comment.