feat: port growth ring, hairball, knife, laser wrench, magnet ring

This commit is contained in:
Michael Hillcox 2021-05-04 18:50:50 +01:00
parent c87bfb6c94
commit 420188975e
7 changed files with 104 additions and 118 deletions

View File

@ -147,7 +147,7 @@ public final class ActuallyItems {
public static final RegistryObject<Item> POTION_RING = ITEMS.register("potion_ring", () -> new ItemPotionRing(false));
public static final RegistryObject<Item> POTION_RING_ADVANCED = ITEMS.register("potion_ring_advanced", () -> new ItemPotionRing(true));
public static final RegistryObject<Item> HAIRY_BALL = ITEMS.register("hairy_ball", ItemHairyBall::new);
public static final RegistryObject<Item> HAIRY_BALL = ITEMS.register("hairy_ball", ItemHairBall::new);
public static final RegistryObject<Item> COFFEE_BEANS = ITEMS.register("coffee_beans", ItemCoffeeBean::new);
public static final RegistryObject<Item> RICE_SEED = ITEMS.register("rice_seed", () -> new ItemSeed("seedRice", ActuallyBlocks.RICE.get(), FOOD.get(), TheFoods.RICE.ordinal()));

View File

@ -13,15 +13,16 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockGrass;
import net.minecraft.block.BlockState;
import net.minecraft.block.GrassBlock;
import net.minecraft.block.IGrowable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.IPlantable;
import java.util.ArrayList;
@ -30,11 +31,11 @@ import java.util.List;
public class ItemGrowthRing extends ItemEnergy {
public ItemGrowthRing() {
super(1000000, 2000, name);
super(1000000, 2000);
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (!(entity instanceof PlayerEntity) || world.isRemote || entity.isSneaking()) {
return;
}
@ -47,17 +48,17 @@ public class ItemGrowthRing extends ItemEnergy {
List<BlockPos> blocks = new ArrayList<>();
//Adding all possible Blocks
if (player.world.getTotalWorldTime() % 30 == 0) {
if (player.world.getGameTime() % 30 == 0) {
int range = 3;
for (int x = -range; x < range + 1; x++) {
for (int z = -range; z < range + 1; z++) {
for (int y = -range; y < range + 1; y++) {
int theX = MathHelper.floor(player.posX + x);
int theY = MathHelper.floor(player.posY + y);
int theZ = MathHelper.floor(player.posZ + z);
int theX = MathHelper.floor(player.getPosX() + x);
int theY = MathHelper.floor(player.getPosY() + y);
int theZ = MathHelper.floor(player.getPosZ() + z);
BlockPos posInQuestion = new BlockPos(theX, theY, theZ);
Block theBlock = world.getBlockState(posInQuestion).getBlock();
if ((theBlock instanceof IGrowable || theBlock instanceof IPlantable) && !(theBlock instanceof BlockGrass)) {
if ((theBlock instanceof IGrowable || theBlock instanceof IPlantable) && !(theBlock instanceof GrassBlock)) {
blocks.add(posInQuestion);
}
}
@ -72,12 +73,11 @@ public class ItemGrowthRing extends ItemEnergy {
BlockState state = world.getBlockState(pos);
Block block = state.getBlock();
int metaBefore = block.getMetaFromState(state);
block.updateTick(world, pos, world.getBlockState(pos), world.rand);
block.tick(world.getBlockState(pos), (ServerWorld) world, pos, world.rand);
//Show Particles if Metadata changed
BlockState newState = world.getBlockState(pos);
if (newState.getBlock().getMetaFromState(newState) != metaBefore) {
if (newState != state) {
world.playEvent(2005, pos, 0);
}
@ -92,9 +92,4 @@ public class ItemGrowthRing extends ItemEnergy {
}
}
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.EPIC;
}
}

View File

@ -15,24 +15,28 @@ import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.passive.OcelotEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Random;
import java.util.UUID;
public class ItemHairyBall extends ItemBase {
public class ItemHairBall extends ItemBase {
private final UUID KittyVanCatUUID = UUID.fromString("681d4e20-10ef-40c9-a0a5-ba2f1995ef44");
public ItemHairyBall() {
public ItemHairBall() {
super();
// TODO: [port] move this.
MinecraftForge.EVENT_BUS.register(this);
}
@ -40,30 +44,41 @@ public class ItemHairyBall extends ItemBase {
public void livingUpdateEvent(LivingEvent.LivingUpdateEvent event) {
//Ocelots dropping Hair Balls
if (ConfigBoolValues.DO_CAT_DROPS.isEnabled() && event.getEntityLiving() != null && event.getEntityLiving().world != null && !event.getEntityLiving().world.isRemote) {
if (event.getEntityLiving() instanceof EntityOcelot && ((EntityOcelot) event.getEntityLiving()).isTamed() || event.getEntityLiving() instanceof PlayerEntity && event.getEntityLiving().getUniqueID().equals(this.KittyVanCatUUID)) {
if (event.getEntityLiving() instanceof OcelotEntity && catIsTamedReflection((OcelotEntity) event.getEntityLiving()) || event.getEntityLiving() instanceof PlayerEntity && event.getEntityLiving().getUniqueID().equals(this.KittyVanCatUUID)) {
if (event.getEntityLiving().world.rand.nextInt(ConfigIntValues.FUR_CHANCE.getValue()) == 0) {
ItemEntity item = new ItemEntity(event.getEntityLiving().world, event.getEntityLiving().posX + 0.5, event.getEntityLiving().posY + 0.5, event.getEntityLiving().posZ + 0.5, new ItemStack(ActuallyItems.HAIRY_BALL));
ItemEntity item = new ItemEntity(event.getEntityLiving().world, event.getEntityLiving().getPosX() + 0.5, event.getEntityLiving().getPosY() + 0.5, event.getEntityLiving().getPosZ() + 0.5, new ItemStack(ActuallyItems.HAIRY_BALL.get()));
event.getEntityLiving().world.addEntity(item);
}
}
}
}
public static boolean catIsTamedReflection(OcelotEntity entity) {
try {
Method isTrusting = OcelotEntity.class.getDeclaredMethod("isTrusting");
return (boolean) isTrusting.invoke(entity);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
ItemStack returnItem = this.getRandomReturnItem(world.rand);
if (!player.inventory.addItemStackToInventory(returnItem)) {
ItemEntity entityItem = new ItemEntity(player.world, player.posX, player.posY, player.posZ, returnItem);
ItemEntity entityItem = new ItemEntity(player.world, player.getPosX(), player.getPosY(), player.getPosZ(), returnItem);
entityItem.setPickupDelay(0);
player.world.addEntity(entityItem);
}
stack.shrink(1);
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, world.rand.nextFloat() * 0.1F + 0.9F);
world.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, world.rand.nextFloat() * 0.1F + 0.9F);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
return ActionResult.resultSuccess(stack);
}
public ItemStack getRandomReturnItem(Random rand) {

View File

@ -12,37 +12,31 @@ package de.ellpeck.actuallyadditions.mod.items;
import com.google.common.collect.Multimap;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ItemStack;
public class ItemKnife extends ItemBase {
public ItemKnife() {
super(name);
this.setMaxDamage(100);
this.setMaxStackSize(1);
this.setContainerItem(this);
this.setNoRepair();
super(ActuallyItems.defaultNonStacking().defaultMaxDamage(100).setNoRepair());
}
@Override
public boolean getShareTag() {
return true;
}
// @Override
// public boolean getShareTag() {
// return true;
// }
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.EPIC;
}
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
Multimap<String, AttributeModifier> map = super.getAttributeModifiers(slot, stack);
if (slot == EntityEquipmentSlot.MAINHAND) {
map.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Knife Modifier", 3, 0));
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlotType slot, ItemStack stack) {
Multimap<Attribute, AttributeModifier> map = super.getAttributeModifiers(slot, stack);
if (slot == EquipmentSlotType.MAINHAND) {
// TODO: [port] validate
map.put(Attributes.ATTACK_DAMAGE, new AttributeModifier("Knife Modifier", 3, AttributeModifier.Operation.ADDITION));
}
return map;
}
@ -50,7 +44,7 @@ public class ItemKnife extends ItemBase {
@Override
public ItemStack getContainerItem(ItemStack stack) {
ItemStack theStack = stack.copy();
theStack.setItemDamage(theStack.getItemDamage() + 1);
theStack.setDamage(theStack.getDamage() + 1);
return theStack;
}
}

View File

@ -14,16 +14,15 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
@ -33,13 +32,16 @@ import java.util.List;
public class ItemLaserWrench extends ItemBase {
public ItemLaserWrench() {
super(name);
this.setMaxStackSize(1);
super(ActuallyItems.defaultNonStacking());
}
@Override
public EnumActionResult onItemUse(PlayerEntity player, World world, BlockPos pos, Hand hand, Direction par7, float par8, float par9, float par10) {
ItemStack stack = player.getHeldItem(hand);
public ActionResultType onItemUse(ItemUseContext context) {
BlockPos pos = context.getPos();
World world = context.getWorld();
PlayerEntity player = context.getPlayer();
ItemStack stack = player.getHeldItem(context.getHand());
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityLaserRelay) {
TileEntityLaserRelay relay = (TileEntityLaserRelay) tile;
@ -65,39 +67,36 @@ public class ItemLaserWrench extends ItemBase {
player.sendStatusMessage(new TranslationTextComponent("tooltip." + ActuallyAdditions.MODID + ".laser.connected.desc"), true);
return EnumActionResult.SUCCESS;
return ActionResultType.SUCCESS;
}
}
player.sendMessage(new TranslationTextComponent("tooltip." + ActuallyAdditions.MODID + ".laser.cantConnect.desc"));
player.sendStatusMessage(new TranslationTextComponent("tooltip." + ActuallyAdditions.MODID + ".laser.cantConnect.desc"), false);
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
}
}
}
return EnumActionResult.SUCCESS;
return ActionResultType.SUCCESS;
}
return EnumActionResult.FAIL;
return ActionResultType.FAIL;
}
@Override
public boolean getShareTag() {
return true;
}
// // TODO: [port] ensure this is correct
// @Nullable
// @Override
// public CompoundNBT getShareTag(ItemStack stack) {
// return new CompoundNBT();
// }
@Override
public void addInformation(ItemStack stack, World playerIn, List<String> list, ITooltipFlag advanced) {
public void addInformation(ItemStack stack, World playerIn, List<ITextComponent> list, ITooltipFlag advanced) {
BlockPos coords = ItemPhantomConnector.getStoredPosition(stack);
if (coords != null) {
list.add(StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".boundTo.desc") + ":");
list.add("X: " + coords.getX());
list.add("Y: " + coords.getY());
list.add("Z: " + coords.getZ());
list.add(TextFormatting.ITALIC + StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".clearStorage.desc"));
list.add(new TranslationTextComponent("tooltip." + ActuallyAdditions.MODID + ".boundTo.desc").appendString(":"));
list.add(new StringTextComponent("X: " + coords.getX()));
list.add(new StringTextComponent("Y: " + coords.getY()));
list.add(new StringTextComponent("Z: " + coords.getZ()));
list.add(new TranslationTextComponent("tooltip." + ActuallyAdditions.MODID + ".clearStorage.desc").mergeStyle(TextFormatting.ITALIC));
}
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.EPIC;
}
}

View File

@ -12,25 +12,20 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.block.*;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.UseAction;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.IForgeShearable;
import java.util.ArrayList;
import java.util.Collections;
@ -47,35 +42,27 @@ public class ItemLeafBlower extends ItemBase implements IDisplayStandItem {
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
player.setActiveHand(hand);
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
return ActionResult.resultSuccess(player.getHeldItem(hand));
}
@Override
public EnumAction getItemUseAction(ItemStack stack) {
return EnumAction.BOW;
public UseAction getUseAction(ItemStack stack) {
return UseAction.BOW;
}
@Override
public int getMaxItemUseDuration(ItemStack stack) {
//Cuz you won't hold it for that long right-clicking anyways
public int getUseDuration(ItemStack stack) {
return Integer.MAX_VALUE;
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return this.isAdvanced
? EnumRarity.EPIC
: EnumRarity.RARE;
}
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int time) {
this.doUpdate(player.world, MathHelper.floor(player.posX), MathHelper.floor(player.posY), MathHelper.floor(player.posZ), time, stack);
public void onUsingTick(ItemStack stack, LivingEntity player, int count) {
this.doUpdate(player.world, MathHelper.floor(player.getPosX()), MathHelper.floor(player.getPosY()), MathHelper.floor(player.getPosZ()), count, stack);
}
private boolean doUpdate(World world, int x, int y, int z, int time, ItemStack stack) {
if (!world.isRemote) {
if (time <= this.getMaxItemUseDuration(stack) && (this.isAdvanced || time % 3 == 0)) {
if (time <= this.getUseDuration(stack) && (this.isAdvanced || time % 3 == 0)) {
//Breaks the Blocks
boolean broke = this.breakStuff(world, x, y, z);
//Plays a Minecart sounds (It really sounds like a Leaf Blower!)
@ -110,7 +97,7 @@ public class ItemLeafBlower extends ItemBase implements IDisplayStandItem {
BlockPos pos = new BlockPos(x + reachX, y + reachY, z + reachZ);
Block block = world.getBlockState(pos).getBlock();
if (block != null && (block instanceof BlockBush || block instanceof IShearable) && (this.isAdvanced || !block.isLeaves(world.getBlockState(pos), world, pos))) {
if ((block instanceof BushBlock || block instanceof IForgeShearable) && (this.isAdvanced || block instanceof LeavesBlock)) {
breakPositions.add(pos);
}
}
@ -123,7 +110,8 @@ public class ItemLeafBlower extends ItemBase implements IDisplayStandItem {
BlockPos theCoord = breakPositions.get(0);
BlockState theState = world.getBlockState(theCoord);
theState.getBlock().dropBlockAsItem(world, theCoord, theState, 0);
world.destroyBlock(theCoord, true);
// theState.getBlock().dropBlockAsItem(world, theCoord, theState, 0);
//Plays the Breaking Sound
world.playEvent(2001, theCoord, Block.getStateId(theState));

View File

@ -15,10 +15,8 @@ import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
@ -28,7 +26,7 @@ import java.util.List;
public class ItemMagnetRing extends ItemEnergy {
public ItemMagnetRing() {
super(200000, 1000, name);
super(200000, 1000);
}
@Override
@ -37,7 +35,7 @@ public class ItemMagnetRing extends ItemEnergy {
}
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (entity instanceof PlayerEntity && !world.isRemote && !ItemUtil.isEnabled(stack)) {
PlayerEntity player = (PlayerEntity) entity;
if (player.isCreative() || player.isSpectator()) {
@ -46,13 +44,14 @@ public class ItemMagnetRing extends ItemEnergy {
if (!entity.isSneaking()) {
//Get all the Items in the area
int range = 5;
List<ItemEntity> items = world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(entity.posX - range, entity.posY - range, entity.posZ - range, entity.posX + range, entity.posY + range, entity.posZ + range));
List<ItemEntity> items = world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(entity.getPosX() - range, entity.getPosY() - range, entity.getPosZ() - range, entity.getPosX() + range, entity.getPosY() + range, entity.getPosZ() + range));
if (!items.isEmpty()) {
for (ItemEntity item : items) {
if (item.getEntityData().getBoolean("PreventRemoteMovement")) {
// TODO: [port] check this data is being saved on the time
if (item.getPersistentData().getBoolean("PreventRemoteMovement")) {
continue;
}
if (!item.isDead && !item.cannotPickup()) {
if (item.isAlive() && !item.cannotPickup()) {
int energyForItem = 50 * item.getItem().getCount();
if (this.getEnergyStored(stack) >= energyForItem) {
@ -61,7 +60,7 @@ public class ItemMagnetRing extends ItemEnergy {
item.onCollideWithPlayer(player);
if (!player.isCreative()) {
if (item.isDead || !ItemStack.areItemStacksEqual(item.getItem(), oldItem)) {
if (!item.isAlive() || !ItemStack.areItemStacksEqual(item.getItem(), oldItem)) {
this.extractEnergyInternal(stack, energyForItem, false);
}
}
@ -77,13 +76,9 @@ public class ItemMagnetRing extends ItemEnergy {
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity player, Hand hand) {
if (!worldIn.isRemote && player.isSneaking()) {
ItemUtil.changeEnabled(player, hand);
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
return ActionResult.resultSuccess(player.getHeldItem(hand));
}
return super.onItemRightClick(worldIn, player, hand);
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.EPIC;
}
}