changed my mind: no interface anymore. doesn't fit the style
Some checks are pending
Build / build (push) Waiting to run
Some checks are pending
Build / build (push) Waiting to run
This commit is contained in:
parent
8be2b08e64
commit
9188fcaef1
9 changed files with 74 additions and 212 deletions
|
@ -5,7 +5,6 @@ import fr.sushi.charmsnfabrics.client.datagen.CnFModelProvider;
|
|||
import fr.sushi.charmsnfabrics.client.model.FlowerCrownModel;
|
||||
import fr.sushi.charmsnfabrics.client.renderer.FloralWorkbenchRenderer;
|
||||
import fr.sushi.charmsnfabrics.client.renderer.FlowerCrownRenderer;
|
||||
import fr.sushi.charmsnfabrics.client.screen.FloralWorkbenchScreen;
|
||||
import fr.sushi.charmsnfabrics.common.CnFRegistries;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
|
@ -13,7 +12,6 @@ import net.neoforged.fml.ModContainer;
|
|||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.neoforged.neoforge.client.event.ContainerScreenEvent;
|
||||
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
|
||||
|
@ -61,9 +59,10 @@ public class CnFClient
|
|||
event.createProvider(CnFModelProvider::new);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
private static void onScreenAttach(RegisterMenuScreensEvent event) {
|
||||
event.register(CnFRegistries.MenuTypes.FLORAL_WB_MENU.get(),
|
||||
FloralWorkbenchScreen::new);
|
||||
}
|
||||
// @SubscribeEvent
|
||||
// private static void onScreenAttach(RegisterMenuScreensEvent event)
|
||||
// {
|
||||
// event.register(CnFRegistries.MenuTypes.FLORAL_WB_MENU.get(),
|
||||
// FloralWorkbenchScreen::new);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package fr.sushi.charmsnfabrics.client.renderer;
|
|||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Axis;
|
||||
import fr.sushi.charmsnfabrics.CharmsAndFabrics;
|
||||
import fr.sushi.charmsnfabrics.client.CnFLayers;
|
||||
import fr.sushi.charmsnfabrics.client.model.FlowerCrownModel;
|
||||
|
@ -11,6 +12,7 @@ import net.minecraft.client.renderer.RenderType;
|
|||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class FloralWorkbenchRenderer implements BlockEntityRenderer<FloralWorkbenchBlockEntity>
|
||||
|
@ -28,14 +30,20 @@ public class FloralWorkbenchRenderer implements BlockEntityRenderer<FloralWorkbe
|
|||
MultiBufferSource bufferSource, int packedLight, int packedOverlay,
|
||||
Vec3 cameraPos)
|
||||
{
|
||||
if (!blockEntity.hasCrown()) {
|
||||
return;
|
||||
}
|
||||
poseStack.pushPose();
|
||||
float yRot =
|
||||
blockEntity.getRandomSource().nextFloat() * (float) Math.PI * partialTick;
|
||||
poseStack.translate(0.5f, 1.625f, 0.5f);
|
||||
// poseStack.rotateAround(Axis.YP.rotationDegrees(yRot), 0.0f, 0.0f, 0.0f);
|
||||
ResourceLocation texture =
|
||||
ResourceLocation.fromNamespaceAndPath(CharmsAndFabrics.MODID,
|
||||
"textures/models/accessory/flower_crown.png");
|
||||
VertexConsumer consumer =
|
||||
bufferSource.getBuffer(RenderType.entityCutout(texture));
|
||||
this.model.renderToBuffer(poseStack, consumer, 0xff, packedOverlay);
|
||||
this.model.renderToBuffer(poseStack, consumer, packedLight, packedOverlay);
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package fr.sushi.charmsnfabrics.client.screen;
|
||||
|
||||
import fr.sushi.charmsnfabrics.CharmsAndFabrics;
|
||||
import fr.sushi.charmsnfabrics.common.inventory.FloralWorkbenchMenu;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class FloralWorkbenchScreen extends AbstractContainerScreen<FloralWorkbenchMenu>
|
||||
{
|
||||
private static final ResourceLocation FLORAL_WB_MENU_LOCATION =
|
||||
ResourceLocation.fromNamespaceAndPath(CharmsAndFabrics.MODID,
|
||||
"textures/gui/container/floral_workbench.png");
|
||||
|
||||
public FloralWorkbenchScreen(FloralWorkbenchMenu menu,
|
||||
Inventory playerInventory, Component title)
|
||||
{
|
||||
super(menu, playerInventory, title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(GuiGraphics guiGraphics, float partialTick,
|
||||
int mouseX, int mouseY)
|
||||
{
|
||||
int halfWidth = (this.width - this.imageWidth) / 2;
|
||||
int halfHeight = (this.height - this.imageHeight) / 2;
|
||||
|
||||
guiGraphics.blit(RenderType::guiTextured, FLORAL_WB_MENU_LOCATION,
|
||||
halfWidth, halfHeight, 0.0F, 0.0F, this.imageWidth,
|
||||
this.imageHeight, 256, 256);
|
||||
|
||||
// if (this.menu.getSlot(0).hasItem() && !this.menu.getSlot(2).hasItem())
|
||||
// {
|
||||
// guiGraphics.blitSprite(RenderType::guiTextured, ERROR_SPRITE,
|
||||
// i + 92, j + 31, 28, 21);
|
||||
// }
|
||||
}
|
||||
}
|
|
@ -3,14 +3,10 @@ package fr.sushi.charmsnfabrics.common;
|
|||
import fr.sushi.charmsnfabrics.CharmsAndFabrics;
|
||||
import fr.sushi.charmsnfabrics.common.block.FloralWorkbench;
|
||||
import fr.sushi.charmsnfabrics.common.entities.block.FloralWorkbenchBlockEntity;
|
||||
import fr.sushi.charmsnfabrics.common.inventory.FloralWorkbenchMenu;
|
||||
import fr.sushi.charmsnfabrics.common.item.FlowerCrown;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
|
@ -19,9 +15,10 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.neoforge.attachment.AttachmentType;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.neoforged.neoforge.registries.*;
|
||||
import net.neoforged.neoforge.registries.DeferredBlock;
|
||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||
import net.neoforged.neoforge.registries.DeferredItem;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -96,40 +93,11 @@ public class CnFRegistries
|
|||
Set.of(Blocks.FLORAL_WORKBENCH.get())));
|
||||
}
|
||||
|
||||
public static class AttachmentTypes
|
||||
{
|
||||
public static final DeferredRegister<AttachmentType<?>>
|
||||
ATTACHMENT_TYPES =
|
||||
DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES,
|
||||
CharmsAndFabrics.MODID);
|
||||
|
||||
public static final Supplier<AttachmentType<ItemStackHandler>>
|
||||
FLORAL_WORKBENCH_DATA =
|
||||
ATTACHMENT_TYPES.register("floral_workbench_data",
|
||||
() -> AttachmentType
|
||||
.serializable(() -> new ItemStackHandler(1))
|
||||
.build());
|
||||
}
|
||||
|
||||
public static class MenuTypes
|
||||
{
|
||||
public static final DeferredRegister<MenuType<?>> MENU_TYPES =
|
||||
DeferredRegister.create(Registries.MENU,
|
||||
CharmsAndFabrics.MODID);
|
||||
|
||||
public static final Supplier<MenuType<FloralWorkbenchMenu>>
|
||||
FLORAL_WB_MENU = MENU_TYPES.register("floral_wb_menu",
|
||||
() -> new MenuType<>(FloralWorkbenchMenu::new,
|
||||
FeatureFlags.DEFAULT_FLAGS));
|
||||
}
|
||||
|
||||
public static void register(IEventBus bus)
|
||||
{
|
||||
Items.ITEMS.register(bus);
|
||||
Blocks.BLOCKS.register(bus);
|
||||
Tabs.CREATIVE_MODE_TABS.register(bus);
|
||||
Entities.BLOCK_ENTITY_TYPES.register(bus);
|
||||
MenuTypes.MENU_TYPES.register(bus);
|
||||
AttachmentTypes.ATTACHMENT_TYPES.register(bus);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package fr.sushi.charmsnfabrics.common.block;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import fr.sushi.charmsnfabrics.common.CnFRegistries;
|
||||
import fr.sushi.charmsnfabrics.common.entities.block.FloralWorkbenchBlockEntity;
|
||||
import fr.sushi.charmsnfabrics.common.inventory.FloralWorkbenchMenu;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
|
@ -28,6 +27,7 @@ import net.minecraft.world.phys.BlockHitResult;
|
|||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -50,9 +50,6 @@ public class FloralWorkbench extends BaseEntityBlock
|
|||
private static final Map<Direction.Axis, VoxelShape> SHAPES =
|
||||
Shapes.rotateHorizontalAxis(Shapes.or(LEGS, TABLE, SUPPORT));
|
||||
|
||||
public static final Component FLORAL_WB_TITLE = Component.translatable(
|
||||
"container.charmsnfabrics.floral_workbench.title");
|
||||
|
||||
public FloralWorkbench(BlockBehaviour.Properties properties)
|
||||
{
|
||||
super(properties);
|
||||
|
@ -104,24 +101,50 @@ public class FloralWorkbench extends BaseEntityBlock
|
|||
Level level, BlockPos pos, Player player, InteractionHand hand,
|
||||
BlockHitResult hitResult)
|
||||
{
|
||||
if (!level.isClientSide())
|
||||
if (level.getBlockEntity(
|
||||
pos) instanceof FloralWorkbenchBlockEntity blockentity)
|
||||
{
|
||||
if (level.getBlockEntity(
|
||||
pos) instanceof FloralWorkbenchBlockEntity blockentity)
|
||||
boolean hasCrown = blockentity.hasCrown();
|
||||
boolean emptyHand = stack.isEmpty();
|
||||
if (!level.isClientSide())
|
||||
{
|
||||
player.openMenu(blockentity);
|
||||
// award stat : "Flowers !"
|
||||
IItemHandler handler = blockentity.getItemHandler();
|
||||
ItemStack crown = handler.getStackInSlot(0);
|
||||
|
||||
if (hasCrown && emptyHand)
|
||||
{
|
||||
Containers.dropItemStack(level, pos.getX(),
|
||||
pos.getY() + 1.0f, pos.getZ(), crown);
|
||||
blockentity.setChanged();
|
||||
return InteractionResult.SUCCESS_SERVER;
|
||||
}
|
||||
else if (stack.is(CnFRegistries.Items.FLOWER_CROWN.get()) &&
|
||||
!hasCrown)
|
||||
{
|
||||
handler.insertItem(0, stack.copy(), false);
|
||||
stack.consume(1, player);
|
||||
blockentity.setChanged();
|
||||
return InteractionResult.CONSUME;
|
||||
} else {
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return hasCrown ^ emptyHand ? InteractionResult.SUCCESS :
|
||||
InteractionResult.FAIL;
|
||||
}
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
else
|
||||
{
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable MenuProvider getMenuProvider(BlockState state,
|
||||
Level level, BlockPos pos)
|
||||
{
|
||||
return new SimpleMenuProvider(
|
||||
(id, inv, player) -> new FloralWorkbenchMenu(id, inv),
|
||||
FLORAL_WB_TITLE);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,19 @@
|
|||
package fr.sushi.charmsnfabrics.common.entities.block;
|
||||
|
||||
import fr.sushi.charmsnfabrics.common.CnFRegistries;
|
||||
import fr.sushi.charmsnfabrics.common.inventory.FloralWorkbenchMenu;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
|
||||
public class FloralWorkbenchBlockEntity extends BaseContainerBlockEntity
|
||||
public class FloralWorkbenchBlockEntity extends BlockEntity
|
||||
{
|
||||
private NonNullList<ItemStack> items = NonNullList.withSize(1, ItemStack.EMPTY);
|
||||
private final RandomSource randomSource = RandomSource.create();
|
||||
private final ItemStackHandler itemHandler = new ItemStackHandler(1);
|
||||
|
||||
public FloralWorkbenchBlockEntity(BlockPos pos, BlockState blockState)
|
||||
{
|
||||
|
@ -30,7 +26,8 @@ public class FloralWorkbenchBlockEntity extends BaseContainerBlockEntity
|
|||
HolderLookup.Provider levelRegistry)
|
||||
{
|
||||
super.saveAdditional(nbt, levelRegistry);
|
||||
ContainerHelper.saveAllItems(nbt, this.items, levelRegistry);
|
||||
CompoundTag tag = itemHandler.serializeNBT(levelRegistry);
|
||||
nbt.put("Inventory", tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,41 +35,23 @@ public class FloralWorkbenchBlockEntity extends BaseContainerBlockEntity
|
|||
HolderLookup.Provider levelRegistry)
|
||||
{
|
||||
super.loadAdditional(nbt, levelRegistry);
|
||||
this.items = NonNullList.withSize(1, ItemStack.EMPTY);
|
||||
ContainerHelper.loadAllItems(nbt, this.items, levelRegistry);
|
||||
// this.crown = items.getFirst();
|
||||
nbt.getCompound("Inventory")
|
||||
.ifPresent(tag -> itemHandler.deserializeNBT(levelRegistry, tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component getDefaultName()
|
||||
public RandomSource getRandomSource()
|
||||
{
|
||||
return Component.translatable(
|
||||
"container.charmsnfabrics.floral_workbench");
|
||||
return this.randomSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NonNullList<ItemStack> getItems()
|
||||
public boolean hasCrown()
|
||||
{
|
||||
return this.items;
|
||||
return this.itemHandler.getStackInSlot(0)
|
||||
.is(CnFRegistries.Items.FLOWER_CROWN.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setItems(NonNullList<ItemStack> items)
|
||||
public IItemHandler getItemHandler()
|
||||
{
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractContainerMenu createMenu(int containerId,
|
||||
Inventory inventory)
|
||||
{
|
||||
return new FloralWorkbenchMenu(containerId, inventory,
|
||||
new ItemStackHandler(this.items));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize()
|
||||
{
|
||||
return 1;
|
||||
return this.itemHandler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
package fr.sushi.charmsnfabrics.common.inventory;
|
||||
|
||||
import fr.sushi.charmsnfabrics.common.CnFRegistries;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FloralWorkbenchMenu extends AbstractContainerMenu
|
||||
{
|
||||
private final IItemHandler items;
|
||||
|
||||
public FloralWorkbenchMenu(int containerId, Inventory playerInv)
|
||||
{
|
||||
this(containerId, playerInv, new ItemStackHandler(1));
|
||||
}
|
||||
|
||||
public FloralWorkbenchMenu(int containerId, Inventory playerInv, IItemHandler itemHandler)
|
||||
{
|
||||
super(CnFRegistries.MenuTypes.FLORAL_WB_MENU.get(), containerId);
|
||||
|
||||
this.items = itemHandler;
|
||||
this.addSlot(new SlotItemHandler(itemHandler, 0, 80, 35));
|
||||
this.addStandardInventorySlots(playerInv, 8, 84);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player player, int index)
|
||||
{
|
||||
Slot slot = this.slots.get(index);
|
||||
if (!slot.hasItem())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack stack = slot.getItem();
|
||||
if (index == 0)
|
||||
{
|
||||
/* From CONTAINER to INV */
|
||||
if (!this.moveItemStackTo(stack, 1, 37, false))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* From INV to CONTAINER */
|
||||
if (!this.moveItemStackTo(stack, 0, 1, false))
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
slot.setChanged();
|
||||
slot.onTake(player, stack);
|
||||
return stack.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -2,8 +2,6 @@
|
|||
"itemGroup.charmsnfabrics": "Charms & Fabrics",
|
||||
"item.charmsnfabrics.flower_crown": "Flower Crown",
|
||||
"item.charmsnfabrics.floral_workbench": "Floral Workbench",
|
||||
"container.charmsnfabrics.floral_workbench": "Floral Workbench",
|
||||
"container.charmsnfabrics.floral_workbench.title": "Floral Workbench",
|
||||
|
||||
"charmsnfabrics.configuration.title": "Charms & Fabrics Configs",
|
||||
"charmsnfabrics.configuration.section.charmsnfabrics.common.toml": "Charms & Fabrics Configs",
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue