fix armor slots
This commit is contained in:
parent
2b9474beaf
commit
cea6c5773b
12 changed files with 51 additions and 20 deletions
|
@ -157,7 +157,7 @@ public abstract class GuiContainer extends Gui
|
|||
}
|
||||
|
||||
Map<Attribute, Float> mods = stack.getAttributeModifiers();
|
||||
mods.putAll(stack.getArmorModifiers(null));
|
||||
mods.putAll(stack.getArmorModifiers(this.gm.player, null));
|
||||
|
||||
if(!mods.isEmpty()) {
|
||||
list.add("");
|
||||
|
|
|
@ -13,6 +13,8 @@ public class LayerArachnoidArmor extends LayerArmor {
|
|||
switch(slot) {
|
||||
case CHESTPLATE:
|
||||
case HELMET:
|
||||
super.setModelPartVisible(model, slot);
|
||||
break;
|
||||
default:
|
||||
model.setVisible(false);
|
||||
break;
|
||||
|
|
|
@ -10,6 +10,7 @@ import common.pathfinding.PathNavigate;
|
|||
import common.pathfinding.PathNavigateClimber;
|
||||
import common.rng.Random;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Equipment;
|
||||
import common.world.World;
|
||||
|
||||
public class EntityArachnoid extends EntityNPC {
|
||||
|
@ -53,6 +54,10 @@ public class EntityArachnoid extends EntityNPC {
|
|||
this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
|
||||
this.tasks.addTask(4, new AISpiderAttack(this, EntityNPC.class));
|
||||
}
|
||||
|
||||
public boolean hasArmorSlot(Equipment slot) {
|
||||
return slot != Equipment.BOOTS && slot != Equipment.LEGGINGS;
|
||||
}
|
||||
|
||||
protected PathNavigate getNewNavigator(World worldIn) {
|
||||
return new PathNavigateClimber(this, worldIn);
|
||||
|
|
|
@ -2,6 +2,7 @@ package common.entity.npc;
|
|||
|
||||
import common.entity.DamageSource;
|
||||
import common.rng.Random;
|
||||
import common.util.Equipment;
|
||||
import common.world.World;
|
||||
|
||||
public class EntityCameraHolder extends EntityNPC {
|
||||
|
@ -12,6 +13,10 @@ public class EntityCameraHolder extends EntityNPC {
|
|||
public int getInventoryCapacity() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean hasArmorSlot(Equipment slot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getBaseHealth(Random rand) {
|
||||
return 1;
|
||||
|
|
|
@ -7,6 +7,7 @@ import common.init.Items;
|
|||
import common.init.SpeciesRegistry;
|
||||
import common.item.ItemStack;
|
||||
import common.rng.Random;
|
||||
import common.util.Equipment;
|
||||
import common.util.Identifyable;
|
||||
import common.world.World;
|
||||
|
||||
|
@ -62,6 +63,10 @@ public class EntityChaosMarine extends EntityNPC {
|
|||
public EntityChaosMarine(World worldIn) {
|
||||
super(worldIn);
|
||||
}
|
||||
|
||||
public boolean hasArmorSlot(Equipment slot) {
|
||||
return slot == Equipment.SHIELD;
|
||||
}
|
||||
|
||||
public Legion getLegion() {
|
||||
Enum legion = this.getNpcClass();
|
||||
|
|
|
@ -1298,7 +1298,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
ItemStack stack = itemEntity.getEntityItem();
|
||||
if(stack.getItem().getRadiation(stack) > 0.0f)
|
||||
return;
|
||||
Equipment[] slots = stack.getItem() instanceof ItemArmor armor ? armor.getArmorType().getPossibleSlots() : new Equipment[] {null};
|
||||
Equipment[] slots = stack.getItem() instanceof ItemArmor armor ? armor.getArmorType().getPossibleSlots(this) : new Equipment[] {null};
|
||||
|
||||
for(Equipment slot : slots) {
|
||||
boolean accept = true;
|
||||
|
@ -1462,12 +1462,12 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
|
||||
if (last != null)
|
||||
{
|
||||
this.removeModifiers(last.getArmorModifiers(slot), -1 - slot.getIndex());
|
||||
this.removeModifiers(last.getArmorModifiers(this, slot), -1 - slot.getIndex());
|
||||
}
|
||||
|
||||
if (current != null)
|
||||
{
|
||||
this.addModifiers(current.getArmorModifiers(slot), -1 - slot.getIndex(), current.getSize());
|
||||
this.addModifiers(current.getArmorModifiers(this, slot), -1 - slot.getIndex(), current.getSize());
|
||||
}
|
||||
|
||||
this.prevArmor[slot.getIndex()] = current == null ? null : current.copy();
|
||||
|
@ -2751,9 +2751,12 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
return false;
|
||||
}
|
||||
|
||||
public int getInventoryCapacity()
|
||||
{
|
||||
return 36;
|
||||
public int getInventoryCapacity() {
|
||||
return 36;
|
||||
}
|
||||
|
||||
public boolean hasArmorSlot(Equipment slot) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// END OTHER
|
||||
|
@ -4204,7 +4207,7 @@ public abstract class EntityNPC extends EntityLiving implements IInventory
|
|||
if(info.items != null) {
|
||||
for(ItemStack stack : info.items) {
|
||||
if(stack.getItem() instanceof ItemArmor armor) {
|
||||
for(Equipment slot : armor.getArmorType().getPossibleSlots()) {
|
||||
for(Equipment slot : armor.getArmorType().getPossibleSlots(this)) {
|
||||
if(this.getArmor(slot) == null) {
|
||||
this.setArmor(slot, stack);
|
||||
break;
|
||||
|
|
|
@ -13,6 +13,7 @@ import common.pathfinding.PathNavigateGround;
|
|||
import common.rng.Random;
|
||||
import common.tags.TagObject;
|
||||
import common.util.BlockPos;
|
||||
import common.util.Equipment;
|
||||
import common.util.ExtMath;
|
||||
import common.util.ParticleType;
|
||||
import common.vars.Vars;
|
||||
|
@ -45,6 +46,10 @@ public class EntitySlime extends EntityNPC
|
|||
public int getInventoryCapacity() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
public boolean hasArmorSlot(Equipment slot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// public boolean isAggressive() {
|
||||
// return true;
|
||||
|
|
|
@ -7,6 +7,7 @@ import common.init.Items;
|
|||
import common.init.SpeciesRegistry;
|
||||
import common.item.ItemStack;
|
||||
import common.rng.Random;
|
||||
import common.util.Equipment;
|
||||
import common.util.Identifyable;
|
||||
import common.world.World;
|
||||
|
||||
|
@ -62,6 +63,10 @@ public class EntitySpaceMarine extends EntityNPC {
|
|||
public EntitySpaceMarine(World worldIn) {
|
||||
super(worldIn);
|
||||
}
|
||||
|
||||
public boolean hasArmorSlot(Equipment slot) {
|
||||
return slot == Equipment.SHIELD;
|
||||
}
|
||||
|
||||
public Legion getLegion() {
|
||||
Enum legion = this.getNpcClass();
|
||||
|
|
|
@ -44,10 +44,10 @@ public class ContainerPlayer extends Container {
|
|||
}
|
||||
public boolean isItemValid(ItemStack stack)
|
||||
{
|
||||
return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(type);
|
||||
return stack != null && stack.getItem() instanceof ItemArmor armor && armor.getArmorType().canUseInSlot(ContainerPlayer.this.thePlayer, type);
|
||||
}
|
||||
public String getTexture() {
|
||||
return type.isRing() ? "ring" : type.getName();
|
||||
return ContainerPlayer.this.thePlayer.hasArmorSlot(type) ? (type.isRing() ? "ring" : type.getName()) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ public class ContainerPlayer extends Container {
|
|||
}
|
||||
|
||||
private int getFreeSlotFor(Equipment type) {
|
||||
for(Equipment slot : type.getPossibleSlots()) {
|
||||
for(Equipment slot : type.getPossibleSlots(this.thePlayer)) {
|
||||
if(!this.inventorySlots.get(5 + slot.getIndex()).getHasStack())
|
||||
return 5 + slot.getIndex();
|
||||
}
|
||||
|
|
|
@ -269,9 +269,9 @@ public final class ItemStack {
|
|||
return map;
|
||||
}
|
||||
|
||||
public Map<Attribute, Float> getArmorModifiers(Equipment slot) {
|
||||
public Map<Attribute, Float> getArmorModifiers(EntityNPC entity, Equipment slot) {
|
||||
Map<Attribute, Float> map = Maps.newEnumMap(Attribute.class);
|
||||
if(this.item instanceof ItemArmor armor && (slot == null || armor.getArmorType().canUseInSlot(slot)))
|
||||
if(this.item instanceof ItemArmor armor && (slot == null || armor.getArmorType().canUseInSlot(entity, slot)))
|
||||
armor.getArmorModifiers(map);
|
||||
return map;
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ItemArmor extends Item {
|
|||
}
|
||||
|
||||
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn) {
|
||||
for(Equipment slot : this.type.getPossibleSlots()) {
|
||||
for(Equipment slot : this.type.getPossibleSlots(playerIn)) {
|
||||
if(playerIn.getArmor(slot) == null) {
|
||||
playerIn.setArmor(slot, itemStackIn.copy(1));
|
||||
itemStackIn.decrSize();
|
||||
|
@ -106,7 +106,7 @@ public class ItemArmor extends Item {
|
|||
public boolean test(EntityNPC entity) {
|
||||
if(!entity.isEntityAlive())
|
||||
return false;
|
||||
for(Equipment slot : ItemArmor.this.type.getPossibleSlots()) {
|
||||
for(Equipment slot : ItemArmor.this.type.getPossibleSlots(entity)) {
|
||||
if(entity.getArmor(slot) == null)
|
||||
return true;
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public class ItemArmor extends Item {
|
|||
|
||||
if(list.size() > 0) {
|
||||
EntityNPC entitylivingbase = list.get(0);
|
||||
for(Equipment slot : this.type.getPossibleSlots()) {
|
||||
for(Equipment slot : this.type.getPossibleSlots(entitylivingbase)) {
|
||||
if(entitylivingbase.getArmor(slot) == null) {
|
||||
entitylivingbase.setArmor(slot, stack.copy(1));
|
||||
stack.decrSize();
|
||||
|
|
|
@ -2,6 +2,7 @@ package common.util;
|
|||
|
||||
import common.enchantment.EnchantmentType;
|
||||
import common.entity.animal.EntityHorse;
|
||||
import common.entity.npc.EntityNPC;
|
||||
import common.entity.types.EntityLiving;
|
||||
import common.init.ToolMaterial;
|
||||
|
||||
|
@ -186,11 +187,11 @@ public enum Equipment implements Identifyable, Displayable {
|
|||
return this.animalType;
|
||||
}
|
||||
|
||||
public Equipment[] getPossibleSlots() {
|
||||
return this.isRing() ? new Equipment[] {RING_LEFT_A, RING_LEFT_B, RING_RIGHT_A, RING_RIGHT_B} : new Equipment[] {this.isArmor() ? this : null};
|
||||
public Equipment[] getPossibleSlots(EntityNPC entity) {
|
||||
return this.isArmor() && !entity.hasArmorSlot(this) ? new Equipment[0] : (this.isRing() ? new Equipment[] {RING_LEFT_A, RING_LEFT_B, RING_RIGHT_A, RING_RIGHT_B} : new Equipment[] {this.isArmor() ? this : null});
|
||||
}
|
||||
|
||||
public boolean canUseInSlot(Equipment slot) {
|
||||
return slot == null || !slot.isArmor() || this == slot || (this.isRing() && slot.isRing());
|
||||
public boolean canUseInSlot(EntityNPC entity, Equipment slot) {
|
||||
return slot == null || !slot.isArmor() || ((this == slot || (this.isRing() && slot.isRing())) && entity.hasArmorSlot(slot));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue