Skip to content

Commit

Permalink
wardrobe menu
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Jan 30, 2025
1 parent a9ecbe8 commit f77c016
Show file tree
Hide file tree
Showing 26 changed files with 399 additions and 134 deletions.
70 changes: 70 additions & 0 deletions src/main/java/com/teammoeg/chorda/menu/slots/ArmorSlot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.teammoeg.chorda.menu.slots;

import com.mojang.datafixers.util.Pair;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.Equipable;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;

public class ArmorSlot extends Slot {
public static final ResourceLocation[] TEXTURE_EMPTY_SLOTS = new ResourceLocation[]{InventoryMenu.EMPTY_ARMOR_SLOT_BOOTS, InventoryMenu.EMPTY_ARMOR_SLOT_LEGGINGS, InventoryMenu.EMPTY_ARMOR_SLOT_CHESTPLATE, InventoryMenu.EMPTY_ARMOR_SLOT_HELMET};
Player owner;
EquipmentSlot equipmentslot;


public ArmorSlot(Player owner, EquipmentSlot equipmentslot,Container pContainer, int pSlot, int pX, int pY) {
super(pContainer, pSlot, pX, pY);
this.owner = owner;
this.equipmentslot = equipmentslot;
}

public void setByPlayer(ItemStack p_270969_) {
onEquipItem(owner, equipmentslot, p_270969_, this.getItem());
super.setByPlayer(p_270969_);
}

void onEquipItem(Player pPlayer, EquipmentSlot pSlot, ItemStack pNewItem, ItemStack pOldItem) {
Equipable equipable = Equipable.get(pNewItem);
if (equipable != null) {
pPlayer.onEquipItem(pSlot, pOldItem, pNewItem);
}

}

/**
* Returns the maximum stack size for a given slot (usually the same as
* getInventoryStackLimit(), but 1 in
* the case of armor slots)
*/
public int getMaxStackSize() {
return 1;
}

/**
* Check if the stack is allowed to be placed in this slot, used for armor slots
* as well as furnace fuel.
*/
public boolean mayPlace(ItemStack p_39746_) {
return p_39746_.canEquip(equipmentslot, owner);
}

/**
* Return whether this slot's stack can be taken from this slot.
*/
public boolean mayPickup(Player p_39744_) {
ItemStack itemstack = this.getItem();
return !itemstack.isEmpty() && !p_39744_.isCreative() && EnchantmentHelper.hasBindingCurse(itemstack) ? false
: super.mayPickup(p_39744_);
}

public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
return Pair.of(InventoryMenu.BLOCK_ATLAS, TEXTURE_EMPTY_SLOTS[equipmentslot.getIndex()]);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.teammoeg.chorda.menu.slots;

import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

public class DynamicIndexHandler extends Slot
{
public DynamicIndexHandler(Container pContainer, int pSlot, int pX, int pY) {
super(pContainer, pSlot, pX, pY);
}

private int index;


@Override
public boolean mayPlace(ItemStack stack)
{
if (stack.isEmpty())
return false;
return true;
}

@Override
public ItemStack getItem()
{
return container.getItem(index);
}

@Override
public void set(ItemStack stack)
{
container.setItem(index, stack);
this.setChanged();
}


@Override
public ItemStack remove(int amount)
{
return this.container.removeItem(index, amount);
}

}
40 changes: 40 additions & 0 deletions src/main/java/com/teammoeg/chorda/menu/slots/OffHandSlot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.teammoeg.chorda.menu.slots;

import com.mojang.datafixers.util.Pair;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.ItemStack;

public class OffHandSlot extends ArmorSlot {



public OffHandSlot(Player owner, Container pContainer, int pSlot, int pX, int pY) {
super(owner, EquipmentSlot.OFFHAND, pContainer, pSlot, pX, pY);
}

@Override
public int getMaxStackSize() {
return container.getMaxStackSize();
}

@Override
public boolean mayPlace(ItemStack p_39746_) {
return true;
}

@Override
public boolean mayPickup(Player p_39744_) {
return true;
}

@Override
public Pair<ResourceLocation, ResourceLocation> getNoItemIcon() {
return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.teammoeg.chorda.util.struct;

import java.util.EnumMap;

import net.minecraft.world.entity.EquipmentSlot;

public class EquipmentSlotMap<T> {
private T defaultSlot;
private EnumMap<EquipmentSlot,T> map=new EnumMap<>(EquipmentSlot.class);


public void put(EquipmentSlot slot,T data) {
if(slot==null)
defaultSlot=data;
else
map.put(slot, data);
};
public T get(EquipmentSlot slot) {
return map.getOrDefault(slot, defaultSlot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.teammoeg.frostedheart.content.climate.heatdevice.generator.t1.T1GeneratorState;
import com.teammoeg.frostedheart.content.climate.heatdevice.generator.t2.T2GeneratorLogic;
import com.teammoeg.frostedheart.content.climate.heatdevice.generator.t2.T2GeneratorState;
import com.teammoeg.frostedheart.content.climate.block.WardrobeScreen;
import com.teammoeg.frostedheart.content.climate.block.ClothesScreen;
import com.teammoeg.frostedheart.content.decoration.RelicChestScreen;
import com.teammoeg.frostedheart.content.incubator.IncubatorT1Screen;
import com.teammoeg.frostedheart.content.incubator.IncubatorT2Screen;
Expand Down Expand Up @@ -53,7 +53,7 @@ public static void init() {
MenuScreens.register(FHMenuTypes.SAUNA.get(), SaunaScreen::new);
MenuScreens.register(FHMenuTypes.INCUBATOR_T1.get(), IncubatorT1Screen::new);
MenuScreens.register(FHMenuTypes.INCUBATOR_T2.get(), IncubatorT2Screen::new);
MenuScreens.register(FHMenuTypes.WARDROBE.get(), WardrobeScreen::new);
MenuScreens.register(FHMenuTypes.WARDROBE.get(), ClothesScreen::new);
}

public static <C extends AbstractContainerMenu, S extends BaseScreen> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.teammoeg.frostedheart.content.steamenergy.sauna.SaunaTileEntity;
import com.teammoeg.frostedheart.content.trade.gui.TradeContainer;
import com.teammoeg.frostedheart.content.climate.block.WardrobeBlockEntity;
import com.teammoeg.frostedheart.content.climate.block.WardrobeContainer;
import com.teammoeg.frostedheart.content.climate.block.ClothesInventoryMenu;

import blusunrize.immersiveengineering.api.multiblocks.blocks.logic.IMultiblockState;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -75,7 +75,7 @@ public interface BEMenuFactory<T extends AbstractContainerMenu, BE extends Block
public static final RegistryObject<MenuType<SaunaContainer>> SAUNA = register(SaunaTileEntity.class, ("sauna_vent"), SaunaContainer::new);
public static final RegistryObject<MenuType<IncubatorT1Container>> INCUBATOR_T1 = register(IncubatorTileEntity.class, ("incubator"), IncubatorT1Container::new);
public static final RegistryObject<MenuType<IncubatorT2Container>> INCUBATOR_T2 = register(HeatIncubatorTileEntity.class, ("heat_incubator"), IncubatorT2Container::new);
public static final RegistryObject<MenuType<WardrobeContainer>> WARDROBE = register(WardrobeBlockEntity.class, ("wardrobe"), WardrobeContainer::new);
public static final RegistryObject<MenuType<ClothesInventoryMenu>> WARDROBE = register(WardrobeBlockEntity.class, ("wardrobe"), ClothesInventoryMenu::new);

@SuppressWarnings("unchecked")
public static <T extends AbstractContainerMenu, BE extends BlockEntity> RegistryObject<MenuType<T>> register(Class<BE> BEClass, String name, BEMenuFactory<T, BE> factory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.teammoeg.frostedheart.FHMain;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraftforge.registries.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
Expand All @@ -31,9 +30,12 @@ public class FHSoundEvents {
public FHSoundEvents() {
}
public static final DeferredRegister<SoundEvent> SOUNDS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, FHMain.MODID);
public static final RegistryObject<SoundEvent> MC_BELL = SOUNDS.register("mc_bell", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(FHMain.MODID, "mc_bell")));
public static final RegistryObject<SoundEvent> MC_ROLL = SOUNDS.register("mc_roll", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(FHMain.MODID, "mc_roll")));
public static final RegistryObject<SoundEvent> ICE_CRACKING = SOUNDS.register("ice_cracking", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(FHMain.MODID, "ice_cracking")));
public static final RegistryObject<SoundEvent> WIND = SOUNDS.register("wind", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(FHMain.MODID, "wind")));

public static final RegistryObject<SoundEvent> MC_BELL = makeReference("mc_bell");
public static final RegistryObject<SoundEvent> MC_ROLL = makeReference("mc_roll");
public static final RegistryObject<SoundEvent> ICE_CRACKING = makeReference("ice_cracking");
public static final RegistryObject<SoundEvent> WIND = makeReference("wind");
public static final RegistryObject<SoundEvent> TFOA = makeReference("the_fall_of_arcana");
public static RegistryObject<SoundEvent> makeReference(String name){
return SOUNDS.register(name, () -> SoundEvent.createVariableRangeEvent(FHMain.rl(name)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2024 TeamMoeg
*
* This file is part of Frosted Heart.
*
* Frosted Heart is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* Frosted Heart is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Frosted Heart. If not, see <https://www.gnu.org/licenses/>.
*
*/

package com.teammoeg.frostedheart.content.climate.block;

import com.teammoeg.chorda.menu.CBaseMenu;
import com.teammoeg.chorda.menu.CBlockEntityMenu;
import com.teammoeg.chorda.menu.slots.ArmorSlot;
import com.teammoeg.chorda.menu.slots.OffHandSlot;
import com.teammoeg.frostedheart.bootstrap.common.FHMenuTypes;
import com.teammoeg.frostedheart.content.climate.player.PlayerTemperatureData;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;

public class ClothesInventoryMenu extends CBaseMenu {

public ClothesInventoryMenu(int id, Inventory inventoryPlayer) {
super(FHMenuTypes.WARDROBE.get(), id,inventoryPlayer.player, 21);

/*for (int j = 0; j < 1; ++j) {
for (int k = 0; k < 13; ++k) {
this.addSlot(new Slot(tile, k + j * 5, 44 + k * 18, 19 + j * 18));
}
}*/
// super.addPlayerInventory(inventoryPlayer, 9, id, id);
PlayerTemperatureData ptd = PlayerTemperatureData.getCapability(inventoryPlayer.player).resolve().get();
int y0=6;
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.HEAD,inventoryPlayer,39,6,y0));
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.CHEST,inventoryPlayer,38,6,y0+18));
this.addSlot(new OffHandSlot(inventoryPlayer.player,inventoryPlayer,40,6,y0+18*2));
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.LEGS,inventoryPlayer,37,6,y0+18*3));
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.FEET,inventoryPlayer,36,6,y0+18*4));

for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.HEAD,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.HEAD), k, 100+k*18, 7));
}
for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.CHEST,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.TORSO), k, 100+k*18, 30));
}
for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.LEGS,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.LEGS), k, 100+k*18, 53));
}
for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.FEET,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.FEET), k, 100+k*18, 76));
}
super.addPlayerInventory(inventoryPlayer, 8, 120, 178);
}
/**
* For use by wardrobe
* */
ClothesInventoryMenu(int id, Inventory inventoryPlayer,int max_slots) {
super(FHMenuTypes.WARDROBE.get(), id,inventoryPlayer.player, max_slots);

/*for (int j = 0; j < 1; ++j) {
for (int k = 0; k < 13; ++k) {
this.addSlot(new Slot(tile, k + j * 5, 44 + k * 18, 19 + j * 18));
}
}*/
// super.addPlayerInventory(inventoryPlayer, 9, id, id);
PlayerTemperatureData ptd = PlayerTemperatureData.getCapability(inventoryPlayer.player).resolve().get();
int y0=6;
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.HEAD,inventoryPlayer,39,6,y0));
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.CHEST,inventoryPlayer,38,6,y0+18));
this.addSlot(new OffHandSlot(inventoryPlayer.player,inventoryPlayer,40,6,y0+18*2));
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.LEGS,inventoryPlayer,37,6,y0+18*3));
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.FEET,inventoryPlayer,36,6,y0+18*4));

for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.HEAD,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.HEAD), k, 100+k*18, 7));
}
for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.CHEST,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.TORSO), k, 100+k*18, 30));
}
for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.LEGS,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.LEGS), k, 100+k*18, 53));
}
for(int k=0;k<4;++k) {
this.addSlot(new ArmorSlot(inventoryPlayer.player,EquipmentSlot.FEET,ptd.clothesOfParts.get(PlayerTemperatureData.BodyPart.FEET), k, 100+k*18, 76));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,35 @@
*/

package com.teammoeg.frostedheart.content.climate.block;

import blusunrize.immersiveengineering.client.gui.IEContainerScreen;
import com.teammoeg.frostedheart.content.climate.block.WardrobeContainer;

import com.teammoeg.chorda.client.ClientUtils;
import com.teammoeg.frostedheart.util.client.FHClientUtils;

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;

public class WardrobeScreen extends IEContainerScreen<WardrobeContainer> {
private static final ResourceLocation TEXTURE = FHClientUtils.makeTextureLocation("wardrobe");
public class ClothesScreen extends IEContainerScreen<ClothesInventoryMenu> {
private static final ResourceLocation TEXTURE = FHClientUtils.makeGuiTextureLocation("changing");

public ClothesScreen(ClothesInventoryMenu inventorySlotsIn, Inventory inv, Component title) {
super(inventorySlotsIn, inv, title, TEXTURE);
super.imageHeight = 202;
}

protected void drawContainerBackgroundPre(GuiGraphics pGuiGraphics, float pPartialTick, int pMouseX, int pMouseY) {
int i = this.leftPos;
int j = this.topPos;
InventoryScreen.renderEntityInInventoryFollowsMouse(pGuiGraphics, i + 60, j + 97, 45, (float) (i + 40) - pMouseX,
(float) (j + 75 - 50) - pMouseY, ClientUtils.getPlayer());
}

public WardrobeScreen(WardrobeContainer inventorySlotsIn, Inventory inv, Component title) {
super(inventorySlotsIn, inv, title,TEXTURE);
}
@Override
protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY)
{
}
}
Loading

0 comments on commit f77c016

Please sign in to comment.