sky tools, part 1

This commit is contained in:
Ellpeck 2020-05-13 15:52:46 +02:00
parent cd740b8485
commit 6473bb81d0
31 changed files with 193 additions and 55 deletions

View file

@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_axe"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:item/sky_chest"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:item/sky_helmet"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_hoe"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:item/sky_pants"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_pickaxe"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "naturesaura:item/sky_shoes"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_shovel"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/handheld",
"textures": {
"layer0": "naturesaura:item/sky_sword"
}
}

View file

@ -7,6 +7,7 @@ import de.ellpeck.naturesaura.api.render.ITrinketItem;
import de.ellpeck.naturesaura.items.tools.ItemArmor; import de.ellpeck.naturesaura.items.tools.ItemArmor;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.reg.ModArmorMaterial;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType; import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -74,7 +75,7 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
source = DamageSource.causePlayerDamage((PlayerEntity) living); source = DamageSource.causePlayerDamage((PlayerEntity) living);
else else
source = DamageSource.MAGIC; source = DamageSource.MAGIC;
boolean infusedSet = ItemArmor.isFullSetEquipped(living, 0); boolean infusedSet = ItemArmor.isFullSetEquipped(living, ModArmorMaterial.INFUSED);
int range = 5; int range = 5;
List<LivingEntity> mobs = worldIn.getEntitiesWithinAABB(LivingEntity.class, new AxisAlignedBB( List<LivingEntity> mobs = worldIn.getEntitiesWithinAABB(LivingEntity.class, new AxisAlignedBB(

View file

@ -49,4 +49,13 @@ public final class ModItems {
public static Item TAINTED_GOLD; public static Item TAINTED_GOLD;
public static Item LOOT_FINDER; public static Item LOOT_FINDER;
public static Item LIGHT_STAFF; public static Item LIGHT_STAFF;
public static Item SKY_PICKAXE;
public static Item SKY_AXE;
public static Item SKY_SHOVEL;
public static Item SKY_HOE;
public static Item SKY_SWORD;
public static Item SKY_HELMET;
public static Item SKY_CHEST;
public static Item SKY_PANTS;
public static Item SKY_SHOES;
} }

View file

@ -2,31 +2,34 @@ package de.ellpeck.naturesaura.items.tools;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModArmorMaterial;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem; import net.minecraft.item.*;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.potion.EffectInstance; import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects; import net.minecraft.potion.Effects;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.*;
import java.util.List;
public class ItemArmor extends ArmorItem implements IModItem { public class ItemArmor extends ArmorItem implements IModItem {
private static List<Item[]> sets; private static final AttributeModifier SKY_MOVEMENT_MODIFIER = new AttributeModifier(UUID.fromString("c1f96acc-e117-4dc1-a351-e196a4de6071"), NaturesAura.MOD_ID + ":sky_movement_speed", 0.15F, AttributeModifier.Operation.MULTIPLY_TOTAL);
private static final Map<IArmorMaterial, Item[]> SETS = new HashMap<>();
private final String baseName; private final String baseName;
public ItemArmor(String baseName, IArmorMaterial materialIn, EquipmentSlotType equipmentSlotIn) { public ItemArmor(String baseName, IArmorMaterial materialIn, EquipmentSlotType equipmentSlotIn) {
@ -36,13 +39,11 @@ public class ItemArmor extends ArmorItem implements IModItem {
ModRegistry.add(this); ModRegistry.add(this);
} }
public static boolean isFullSetEquipped(LivingEntity entity, int setIndex) { public static boolean isFullSetEquipped(LivingEntity entity, IArmorMaterial material) {
if (sets == null) { Item[] set = SETS.computeIfAbsent(material, m -> ForgeRegistries.ITEMS.getValues().stream()
sets = new ArrayList<>(); .filter(i -> i instanceof ItemArmor && ((ItemArmor) i).getArmorMaterial() == material)
sets.add(new Item[]{ModItems.INFUSED_IRON_SHOES, ModItems.INFUSED_IRON_PANTS, ModItems.INFUSED_IRON_CHEST, ModItems.INFUSED_IRON_HELMET}); .sorted(Comparator.comparingInt(i -> ((ItemArmor) i).getEquipmentSlot().ordinal()))
} .toArray(Item[]::new));
Item[] set = sets.get(setIndex);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
EquipmentSlotType slot = EquipmentSlotType.values()[i + 2]; EquipmentSlotType slot = EquipmentSlotType.values()[i + 2];
ItemStack stack = entity.getItemStackFromSlot(slot); ItemStack stack = entity.getItemStackFromSlot(slot);
@ -69,12 +70,33 @@ public class ItemArmor extends ArmorItem implements IModItem {
public void onAttack(LivingAttackEvent event) { public void onAttack(LivingAttackEvent event) {
LivingEntity entity = event.getEntityLiving(); LivingEntity entity = event.getEntityLiving();
if (!entity.world.isRemote) { if (!entity.world.isRemote) {
if (!isFullSetEquipped(entity, 0)) if (!isFullSetEquipped(entity, ModArmorMaterial.INFUSED))
return; return;
Entity source = event.getSource().getTrueSource(); Entity source = event.getSource().getTrueSource();
if (source instanceof LivingEntity) if (source instanceof LivingEntity)
((LivingEntity) source).addPotionEffect(new EffectInstance(Effects.WITHER, 40)); ((LivingEntity) source).addPotionEffect(new EffectInstance(Effects.WITHER, 40));
} }
} }
@SubscribeEvent
public void update(TickEvent.PlayerTickEvent event) {
PlayerEntity player = event.player;
IAttributeInstance speed = player.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);
String key = NaturesAura.MOD_ID + ":sky_equipped";
CompoundNBT nbt = player.getPersistentData();
boolean equipped = isFullSetEquipped(player, ModArmorMaterial.SKY);
if (equipped && !nbt.getBoolean(key)) {
// we just equipped it
nbt.putBoolean(key, true);
player.stepHeight = 1.1F;
if (!speed.hasModifier(SKY_MOVEMENT_MODIFIER))
speed.applyModifier(SKY_MOVEMENT_MODIFIER);
} else if (!equipped && nbt.getBoolean(key)) {
// we just unequipped it
nbt.putBoolean(key, false);
player.stepHeight = 0.6F;
speed.removeModifier(SKY_MOVEMENT_MODIFIER);
}
}
} }
} }

View file

@ -43,9 +43,7 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
@Nullable @Nullable
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
if (this == ModItems.INFUSED_IRON_AXE)
return Helper.makeRechargeProvider(stack, true); return Helper.makeRechargeProvider(stack, true);
else return null;
} }
@Override @Override

View file

@ -7,12 +7,22 @@ import de.ellpeck.naturesaura.items.ModItems;
import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.ICustomItemModel;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry; import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.block.BlockState;
import net.minecraft.block.BushBlock;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -30,31 +40,69 @@ public class ItemHoe extends HoeItem implements IModItem, ICustomItemModel {
@Override @Override
public ActionResultType onItemUse(ItemUseContext context) { public ActionResultType onItemUse(ItemUseContext context) {
World world = context.getWorld(); if (this == ModItems.INFUSED_IRON_HOE) {
ActionResultType result = super.onItemUse(context); World world = context.getWorld();
if (!world.isRemote && result == ActionResultType.SUCCESS && this == ModItems.INFUSED_IRON_HOE) { ActionResultType result = super.onItemUse(context);
ItemStack seed = ItemStack.EMPTY; if (!world.isRemote && result == ActionResultType.SUCCESS) {
Random random = world.getRandom(); ItemStack seed = ItemStack.EMPTY;
BlockPos pos = context.getPos(); Random random = world.getRandom();
if (random.nextInt(5) == 0) { BlockPos pos = context.getPos();
seed = new ItemStack(Items.WHEAT_SEEDS); if (random.nextInt(5) == 0) {
} else if (random.nextInt(10) == 0) { seed = new ItemStack(Items.WHEAT_SEEDS);
int rand = random.nextInt(3); } else if (random.nextInt(10) == 0) {
if (rand == 0) { int rand = random.nextInt(3);
seed = new ItemStack(Items.MELON_SEEDS); if (rand == 0) {
} else if (rand == 1) { seed = new ItemStack(Items.MELON_SEEDS);
seed = new ItemStack(Items.PUMPKIN_SEEDS); } else if (rand == 1) {
} else if (rand == 2) { seed = new ItemStack(Items.PUMPKIN_SEEDS);
seed = new ItemStack(Items.BEETROOT_SEEDS); } else if (rand == 2) {
seed = new ItemStack(Items.BEETROOT_SEEDS);
}
}
if (!seed.isEmpty()) {
ItemEntity item = new ItemEntity(world, pos.getX() + random.nextFloat(), pos.getY() + 1F, pos.getZ() + random.nextFloat(), seed);
world.addEntity(item);
} }
} }
return result;
} else if (this == ModItems.SKY_HOE) {
boolean success = false;
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
BlockPos offset = context.getPos().add(x, 0, z);
BlockRayTraceResult newResult = new BlockRayTraceResult(context.getHitVec(), context.getFace(), offset, context.isInside());
ItemUseContext newContext = new ItemUseContext(context.getPlayer(), context.getHand(), newResult);
success |= super.onItemUse(newContext) == ActionResultType.SUCCESS;
}
}
return success ? ActionResultType.SUCCESS : ActionResultType.FAIL;
}
return super.onItemUse(context);
}
if (!seed.isEmpty()) { @Override
ItemEntity item = new ItemEntity(world, pos.getX() + random.nextFloat(), pos.getY() + 1F, pos.getZ() + random.nextFloat(), seed); public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, PlayerEntity player) {
world.addEntity(item); if (stack.getItem() == ModItems.SKY_HOE) {
if (!(player.world.getBlockState(pos).getBlock() instanceof BushBlock))
return false;
if (!player.world.isRemote) {
int range = 3;
for (int x = -range; x <= range; x++) {
for (int y = -range; y <= range; y++) {
for (int z = -range; z <= range; z++) {
if (x == 0 && y == 0 && z == 0)
continue;
BlockPos offset = pos.add(x, y, z);
BlockState otherState = player.world.getBlockState(offset);
if (otherState.getBlock() instanceof BushBlock)
player.world.destroyBlock(offset, true);
}
}
}
} }
} }
return result; return false;
} }
@Override @Override
@ -65,9 +113,7 @@ public class ItemHoe extends HoeItem implements IModItem, ICustomItemModel {
@Nullable @Nullable
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
if (this == ModItems.INFUSED_IRON_HOE) return Helper.makeRechargeProvider(stack, true);
return Helper.makeRechargeProvider(stack, true);
else return null;
} }
@Override @Override

View file

@ -68,9 +68,7 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
@Nullable @Nullable
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
if (this == ModItems.INFUSED_IRON_PICKAXE) return Helper.makeRechargeProvider(stack, true);
return Helper.makeRechargeProvider(stack, true);
else return null;
} }
@Override @Override

View file

@ -86,9 +86,7 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
@Nullable @Nullable
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
if (this == ModItems.INFUSED_IRON_SHOVEL) return Helper.makeRechargeProvider(stack, true);
return Helper.makeRechargeProvider(stack, true);
else return null;
} }
@Override @Override

View file

@ -34,17 +34,18 @@ public class ItemSword extends SwordItem implements IModItem, ICustomItemModel {
@Override @Override
public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) { public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (this == ModItems.INFUSED_IRON_SWORD) if (this == ModItems.INFUSED_IRON_SWORD) {
target.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 60, 2)); target.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 60, 2));
} else if (this == ModItems.SKY_SWORD) {
target.addPotionEffect(new EffectInstance(Effects.LEVITATION, 60, 2));
}
return super.hitEntity(stack, target, attacker); return super.hitEntity(stack, target, attacker);
} }
@Nullable @Nullable
@Override @Override
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) {
if (this == ModItems.INFUSED_IRON_SWORD) return Helper.makeRechargeProvider(stack, true);
return Helper.makeRechargeProvider(stack, true);
else return null;
} }
@Override @Override

View file

@ -15,7 +15,8 @@ import java.util.function.Supplier;
public enum ModArmorMaterial implements IArmorMaterial { public enum ModArmorMaterial implements IArmorMaterial {
INFUSED(NaturesAura.MOD_ID + ":infused_iron", 19, new int[]{2, 5, 6, 2}, 16, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 0F, () -> Ingredient.fromItems(ModItems.INFUSED_IRON)); INFUSED(NaturesAura.MOD_ID + ":infused_iron", 19, new int[]{2, 5, 6, 2}, 16, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 0, () -> Ingredient.fromItems(ModItems.INFUSED_IRON)),
SKY(NaturesAura.MOD_ID + ":sky", 33, new int[]{3, 6, 8, 3}, 12, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 2, () -> Ingredient.fromItems(ModItems.SKY_INGOT));
private static final int[] MAX_DAMAGE_ARRAY = new int[]{13, 15, 16, 11}; private static final int[] MAX_DAMAGE_ARRAY = new int[]{13, 15, 16, 11};
private final String name; private final String name;

View file

@ -8,7 +8,8 @@ import net.minecraft.util.LazyValue;
import java.util.function.Supplier; import java.util.function.Supplier;
public enum ModItemTier implements IItemTier { public enum ModItemTier implements IItemTier {
INFUSED(2, 250, 6.0F, 2.0F, 14, () -> Ingredient.fromItems(ModItems.INFUSED_IRON)); INFUSED(2, 250, 6, 2, 16, () -> Ingredient.fromItems(ModItems.INFUSED_IRON)),
SKY(3, 1500, 8, 3, 12, () -> Ingredient.fromItems(ModItems.SKY_INGOT));
private final int harvestLevel; private final int harvestLevel;
private final int maxUses; private final int maxUses;

View file

@ -205,7 +205,16 @@ public final class ModRegistry {
new ItemDeathRing(), new ItemDeathRing(),
new ItemImpl("tainted_gold"), new ItemImpl("tainted_gold"),
new ItemLootFinder(), new ItemLootFinder(),
new ItemLightStaff() new ItemLightStaff(),
new ItemPickaxe("sky_pickaxe", ModItemTier.SKY, 1, -2.8F),
new ItemAxe("sky_axe", ModItemTier.SKY, 5.0F, -3.0F),
new ItemShovel("sky_shovel", ModItemTier.SKY, 1.5F, -3.0F),
new ItemHoe("sky_hoe", ModItemTier.SKY, -1.0F),
new ItemSword("sky_sword", ModItemTier.SKY, 3, -2.4F),
new ItemArmor("sky_helmet", ModArmorMaterial.SKY, EquipmentSlotType.HEAD),
new ItemArmor("sky_chest", ModArmorMaterial.SKY, EquipmentSlotType.CHEST),
new ItemArmor("sky_pants", ModArmorMaterial.SKY, EquipmentSlotType.LEGS),
new ItemArmor("sky_shoes", ModArmorMaterial.SKY, EquipmentSlotType.FEET)
); );
Helper.populateObjectHolders(ModItems.class, event.getRegistry()); Helper.populateObjectHolders(ModItems.class, event.getRegistry());
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B