mirror of
https://github.com/JonasunderscoreJones/NotEnoughCursedness.git
synced 2025-10-23 12:39:19 +02:00
Merge branch 'the_point_of_the_mask' into thiccc-resolve-conflict
This commit is contained in:
commit
aecfaf8e8e
9 changed files with 256 additions and 0 deletions
|
@ -0,0 +1,10 @@
|
|||
package me.jonasjones.nec.entity.damage;
|
||||
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
|
||||
public class ModDamageSource /*extends DamageSource*/ {
|
||||
|
||||
//protected ModDamageSource(String name) {
|
||||
// super(name);
|
||||
//}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package me.jonasjones.nec.item;
|
||||
|
||||
import me.jonasjones.nec.item.items.MaskItem;
|
||||
import me.jonasjones.nec.item.materials.DirtToolMaterial;
|
||||
import me.jonasjones.nec.item.materials.MaskArmorMaterial;
|
||||
import me.jonasjones.nec.util.ModRegistries;
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.minecraft.item.*;
|
||||
|
@ -15,6 +17,7 @@ public class ModItems {
|
|||
private static Item LETTER_ITEM;
|
||||
private static Item CHAINMAIL_ITEM;
|
||||
private static Item AK47_ITEM;
|
||||
private static Item MASK_ITEM;
|
||||
|
||||
public static void register() {
|
||||
ToolItem DIRT_SWORD = new SwordItem(DirtToolMaterial.INSTANCE, 1, -3.0F, new Item.Settings());
|
||||
|
@ -40,5 +43,10 @@ public class ModItems {
|
|||
Item AK47 = new Item(new FabricItemSettings());
|
||||
AK47_ITEM = Registry.register(Registries.ITEM, new Identifier("nec", "ak_47"), AK47);
|
||||
ModRegistries.register_item(AK47_ITEM);
|
||||
|
||||
ArmorMaterial MaskArmorMaterial = new MaskArmorMaterial();
|
||||
MaskItem MASK = new MaskItem(MaskArmorMaterial, MaskItem.Type.HELMET, new Item.Settings());
|
||||
MASK_ITEM = Registry.register(Registries.ITEM, new Identifier("nec", "mask"), MASK);
|
||||
ModRegistries.register_item(MASK_ITEM);
|
||||
}
|
||||
}
|
||||
|
|
159
src/main/java/me/jonasjones/nec/item/items/MaskItem.java
Normal file
159
src/main/java/me/jonasjones/nec/item/items/MaskItem.java
Normal file
|
@ -0,0 +1,159 @@
|
|||
//
|
||||
// Source code recreated from a .class file by IntelliJ IDEA
|
||||
// (powered by FernFlower decompiler)
|
||||
//
|
||||
|
||||
package me.jonasjones.nec.item.items;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.jonasjones.nec.entity.damage.ModDamageSource;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
import net.minecraft.block.dispenser.ItemDispenserBehavior;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.EntityAttribute;
|
||||
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.attribute.EntityAttributeModifier.Operation;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.mob.MobEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ArmorMaterial;
|
||||
import net.minecraft.item.Equipment;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class MaskItem extends Item implements Equipment {
|
||||
private static final EnumMap<Type, UUID> MODIFIERS = (EnumMap)Util.make(new EnumMap(Type.class), (uuidMap) -> {
|
||||
uuidMap.put(MaskItem.Type.HELMET, UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150"));
|
||||
});
|
||||
public static final DispenserBehavior DISPENSER_BEHAVIOR = new ItemDispenserBehavior() {
|
||||
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
|
||||
return MaskItem.dispenseArmor(pointer, stack) ? stack : super.dispenseSilently(pointer, stack);
|
||||
}
|
||||
};
|
||||
protected final Type type;
|
||||
private final int protection;
|
||||
private final float toughness;
|
||||
protected final float knockbackResistance;
|
||||
protected final ArmorMaterial material;
|
||||
private final Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers;
|
||||
|
||||
public static boolean dispenseArmor(BlockPointer pointer, ItemStack armor) {
|
||||
BlockPos blockPos = pointer.getPos().offset((Direction)pointer.getBlockState().get(DispenserBlock.FACING));
|
||||
List<LivingEntity> list = pointer.getWorld().getEntitiesByClass(LivingEntity.class, new Box(blockPos), EntityPredicates.EXCEPT_SPECTATOR.and(new EntityPredicates.Equipable(armor)));
|
||||
if (list.isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
LivingEntity livingEntity = (LivingEntity)list.get(0);
|
||||
EquipmentSlot equipmentSlot = MobEntity.getPreferredEquipmentSlot(armor);
|
||||
ItemStack itemStack = armor.split(1);
|
||||
livingEntity.equipStack(equipmentSlot, itemStack);
|
||||
if (livingEntity instanceof MobEntity) {
|
||||
((MobEntity)livingEntity).setEquipmentDropChance(equipmentSlot, 2.0F);
|
||||
((MobEntity)livingEntity).setPersistent();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public MaskItem(ArmorMaterial material, Type type, Item.Settings settings) {
|
||||
super(settings);
|
||||
this.material = material;
|
||||
this.type = type;
|
||||
this.protection = 0;
|
||||
this.toughness = material.getToughness();
|
||||
this.knockbackResistance = material.getKnockbackResistance();
|
||||
DispenserBlock.registerBehavior(this, DISPENSER_BEHAVIOR);
|
||||
ImmutableMultimap.Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder();
|
||||
UUID uUID = (UUID)MODIFIERS.get(type);
|
||||
builder.put(EntityAttributes.GENERIC_ARMOR, new EntityAttributeModifier(uUID, "Armor modifier", (double)this.protection, Operation.ADDITION));
|
||||
builder.put(EntityAttributes.GENERIC_ARMOR_TOUGHNESS, new EntityAttributeModifier(uUID, "Armor toughness", (double)this.toughness, Operation.ADDITION));
|
||||
|
||||
this.attributeModifiers = builder.build();
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public int getEnchantability() {
|
||||
return this.material.getEnchantability();
|
||||
}
|
||||
|
||||
public ArmorMaterial getMaterial() {
|
||||
return this.material;
|
||||
}
|
||||
|
||||
public boolean canRepair(ItemStack stack, ItemStack ingredient) {
|
||||
return this.material.getRepairIngredient().test(ingredient) || super.canRepair(stack, ingredient);
|
||||
}
|
||||
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
|
||||
//user.damage(new DamageSource(Registry.register(Registries.ITEM, new Identifier("nec", "custom_death_message"), Text.translatable("death.attack.custom")).setDeathMessage(Text.translatable("death.attack.custom")), Float.MAX_VALUE);
|
||||
return this.equipAndSwap(this, world, user, hand);
|
||||
}
|
||||
|
||||
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
|
||||
return slot == this.type.getEquipmentSlot() ? this.attributeModifiers : super.getAttributeModifiers(slot);
|
||||
}
|
||||
|
||||
public int getProtection() {
|
||||
return this.protection;
|
||||
}
|
||||
|
||||
public float getToughness() {
|
||||
return this.toughness;
|
||||
}
|
||||
|
||||
public EquipmentSlot getSlotType() {
|
||||
return this.type.getEquipmentSlot();
|
||||
}
|
||||
|
||||
public SoundEvent getEquipSound() {
|
||||
return this.getMaterial().getEquipSound();
|
||||
}
|
||||
|
||||
public static enum Type {
|
||||
HELMET(EquipmentSlot.HEAD, "helmet");
|
||||
|
||||
private final EquipmentSlot equipmentSlot;
|
||||
private final String name;
|
||||
|
||||
private Type(EquipmentSlot equipmentSlot, String name) {
|
||||
this.equipmentSlot = equipmentSlot;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public EquipmentSlot getEquipmentSlot() {
|
||||
return this.equipmentSlot;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package me.jonasjones.nec.item.materials;
|
||||
|
||||
import net.minecraft.item.ArmorItem;
|
||||
import net.minecraft.item.ArmorMaterial;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class MaskArmorMaterial implements ArmorMaterial {
|
||||
public static final MaskArmorMaterial INSTANCE = new MaskArmorMaterial();
|
||||
private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11};
|
||||
private static final int[] PROTECTION_VALUES = new int[] {1, 2, 3, 1};
|
||||
@Override
|
||||
public int getDurability(ArmorItem.Type type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProtection(ArmorItem.Type type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantability() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getEquipSound() {
|
||||
return SoundEvents.ITEM_ARMOR_EQUIP_LEATHER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ingredient getRepairIngredient() {
|
||||
return Ingredient.ofItems(Registries.ITEM.get(Identifier.tryParse("mask")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "mask";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getToughness() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackResistance() {
|
||||
return 0;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 204 B |
7
src/main/resources/assets/nec/models/item/mask.json
Normal file
7
src/main/resources/assets/nec/models/item/mask.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "nec:item/mask",
|
||||
"layer1": "minecraft:textures/models/armor/name_layer_1.png"
|
||||
}
|
||||
}
|
BIN
src/main/resources/assets/nec/textures/item/mask.png
Normal file
BIN
src/main/resources/assets/nec/textures/item/mask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 290 B |
BIN
src/main/resources/assets/nec/textures/models/mask_layer_1.png
Normal file
BIN
src/main/resources/assets/nec/textures/models/mask_layer_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 203 B |
17
src/main/resources/data/nec/recipes/mask.json
Normal file
17
src/main/resources/data/nec/recipes/mask.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"ABA"
|
||||
],
|
||||
"key": {
|
||||
"A": {
|
||||
"item": "minecraft:string"
|
||||
},
|
||||
"B": {
|
||||
"item": "minecraft:light_blue_carpet"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "nec:mask"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue