-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
399 additions
and
134 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/main/java/com/teammoeg/chorda/menu/slots/ArmorSlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()]); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/teammoeg/chorda/menu/slots/DynamicIndexHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
src/main/java/com/teammoeg/chorda/menu/slots/OffHandSlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/teammoeg/chorda/util/struct/EquipmentSlotMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/java/com/teammoeg/frostedheart/content/climate/block/ClothesInventoryMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.