Skip to content

Commit

Permalink
feat(infinity-tools): add config options and functionalities for infi…
Browse files Browse the repository at this point in the history
…nity tools

- Implement config options for enabling/disabling the merge of matter clusters.
- Add functionalities for infinity tools to switch between different modes:
  - Infinity Bow: Switch between Range and Trace Attack modes.
  - Infinity Pickaxe: Switch between Base and Range modes.
  - Infinity Shovel: Switch between Base and Range modes.  - Infinity Hoe: Switch between Base and Range modes.
  - Infinity Axe: Switch between Base and Range modes.- Provide in-game feedback for tool mode switching.
- Register custom EMC values for neutron piles and vanilla totems via ProjectE API.
- Rename `InfinityRingItem` to `NeutronRingItem` to reflect its new purpose.
- Update language files to include new tooltips and config options.
  • Loading branch information
cnlimiter committed Aug 4, 2024
1 parent a47c679 commit 712bf18
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package committee.nova.mods.avaritia.api.common.item;

import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;

import java.util.function.Function;

Expand All @@ -19,4 +25,15 @@ public BaseItem() {
public BaseItem(Function<Properties, Properties> properties) {
super(properties.apply(new Properties()));
}

public @NotNull InteractionResultHolder<ItemStack> rightClick(@NotNull Level world, Player player, @NotNull InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
return InteractionResultHolder.pass(stack);
}

@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, @NotNull Player pPlayer, @NotNull InteractionHand pUsedHand) {
if (pPlayer.isCrouching()) return rightClick(pLevel, pPlayer, pUsedHand);
return super.use(pLevel, pPlayer, pUsedHand);
}
}

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/committee/nova/mods/avaritia/api/iface/INbt.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean isDamageable(ItemStack stack) {
}

@Override
public boolean isEnderMask(ItemStack stack, Player player, EnderMan endermanEntity) {
public boolean isEnderMask(ItemStack stack, Player player, EnderMan enderMan) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* @CreateTime: 2024/8/2 上午12:32
* @Description:
*/
public class InfinityRingItem extends ResourceItem {
public class NeutronRingItem extends ResourceItem {


public InfinityRingItem() {
super(Rarity.EPIC, "infinity_ring", true, new Properties().stacksTo(1));
public NeutronRingItem() {
super(Rarity.EPIC, "neutron_ring", true, new Properties().stacksTo(1));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import committee.nova.mods.avaritia.init.registry.ModTiers;
import committee.nova.mods.avaritia.util.ToolUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -70,7 +73,12 @@ public int getEnchantmentValue(ItemStack stack) {
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, Player player, @NotNull InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if (player.isCrouching()) {
CompoundTag tags = stack.getOrCreateTag();
tags.putBoolean("range", !tags.getBoolean("range"));
player.swing(hand);
if(!pLevel.isClientSide && player instanceof ServerPlayer serverPlayer) serverPlayer.sendSystemMessage(
Component.translatable(tags.getBoolean("range") ? "tooltip.infinity_axe.type_2" : "tooltip.infinity_axe.type_1"
), true);
return InteractionResultHolder.success(stack);
}
return super.use(pLevel, player, hand);
Expand All @@ -79,10 +87,8 @@ public int getEnchantmentValue(ItemStack stack) {
@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
Level world = player.level();
if (!world.isClientSide) {
if (player.isCrouching() && canHarvest(pos, world)) {
destroyTree(player, (ServerLevel) world, pos, stack);
}
if (!world.isClientSide && stack.getOrCreateTag().getBoolean("range") && canHarvest(pos, world)) {
destroyTree(player, (ServerLevel) world, pos, stack);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import committee.nova.mods.avaritia.init.registry.ModEntities;
import committee.nova.mods.avaritia.init.registry.ModItems;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
Expand Down Expand Up @@ -103,7 +105,10 @@ public Entity createEntity(Level level, Entity location, ItemStack stack) {
if (player.isCrouching()) {
CompoundTag tags = itemstack.getOrCreateTag();
tags.putBoolean("tracer", !tags.getBoolean("tracer"));
player.setMainArm(HumanoidArm.RIGHT);
player.swing(hand);
if(!level.isClientSide && player instanceof ServerPlayer serverPlayer) serverPlayer.sendSystemMessage(
Component.translatable(tags.getBoolean("tracer") ? "tooltip.infinity_bow.type_2" : "tooltip.infinity_bow.type_1"
), true);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack);
}
player.startUsingItem(hand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import committee.nova.mods.avaritia.util.ClustersUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -69,11 +72,20 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
}

@Override
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level world, @NotNull Player pPlayer, @NotNull InteractionHand pUsedHand) {
ItemStack heldItem = pPlayer.getItemInHand(pUsedHand);
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level world, @NotNull Player player, @NotNull InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if (player.isCrouching()) {
CompoundTag tags = stack.getOrCreateTag();
tags.putBoolean("sow", !tags.getBoolean("sow"));
player.swing(hand);
if(!world.isClientSide && player instanceof ServerPlayer serverPlayer) serverPlayer.sendSystemMessage(
Component.translatable(tags.getBoolean("sow") ? "tooltip.infinity_hoe.type_2" : "tooltip.infinity_hoe.type_1"
), true);
return InteractionResultHolder.success(stack);
}
if (!world.isClientSide) {
pPlayer.swing(InteractionHand.MAIN_HAND);
BlockPos blockPos = pPlayer.getOnPos();
player.swing(hand);
BlockPos blockPos = player.getOnPos();
int rang = 7;
int height = 2;
BlockPos minPos = blockPos.offset(-rang, -height, -rang);
Expand All @@ -85,23 +97,23 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
//harvest
if (block instanceof CropBlock) { //common
if (block instanceof BeetrootBlock ? state.getValue(BeetrootBlock.AGE) >= 3 : state.getValue(CropBlock.AGE) >= 7) {
ClustersUtils.putMapDrops(world, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(world, pos, player, new ItemStack(this), map);
world.setBlock(pos, state.setValue(block instanceof BeetrootBlock ? BeetrootBlock.AGE : CropBlock.AGE, 0), 11);
}
}
if (block instanceof CocoaBlock) { //coca
if (state.getValue(CocoaBlock.AGE) >= 2) {
ClustersUtils.putMapDrops(world, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(world, pos, player, new ItemStack(this), map);
world.setBlock(pos, state.setValue(CocoaBlock.AGE, 0), 11);
}
}
if (block instanceof StemGrownBlock) { //pumpkin
ClustersUtils.putMapDrops(world, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(world, pos, player, new ItemStack(this), map);
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
}
if (block instanceof SweetBerryBushBlock) { //SweetBerry
if (state.getValue(SweetBerryBushBlock.AGE) >= 3) {
ClustersUtils.putMapDrops(world, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(world, pos, player, new ItemStack(this), map);
world.setBlock(pos, state.setValue(SweetBerryBushBlock.AGE, 0), 11);
}
}
Expand All @@ -110,33 +122,33 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
for (int i = 0; i < 3; i++)
bonemealableBlock.isBonemealSuccess(world, world.random, pos, state);
}
ClustersUtils.spawnClusters(world, pPlayer, map);
ClustersUtils.spawnClusters(world, player, map);

}
pPlayer.getCooldowns().addCooldown(heldItem.getItem(), 20);
player.getCooldowns().addCooldown(stack.getItem(), 20);
}
world.playSound(pPlayer, pPlayer.getOnPos(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1.0f, 5.0f);
return InteractionResultHolder.pass(heldItem);
world.playSound(player, player.getOnPos(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1.0f, 5.0f);
return InteractionResultHolder.pass(stack);

}

@Override
public @NotNull InteractionResult useOn(UseOnContext context) {
var stack = context.getItemInHand();
var world = context.getLevel();
var blockpos = context.getClickedPos();
var block1 = world.getBlockState(blockpos).getBlock();
var targetBlock = world.getBlockState(blockpos).getBlock();
var player = context.getPlayer();
var blockstate = Blocks.FARMLAND.defaultBlockState().setValue(FarmBlock.MOISTURE, 7);
int rang = 5;
var minPos = blockpos.offset(-rang, 0, -rang);
var maxPos = blockpos.offset(rang, 0, rang);
// int hook = net.minecraftforge.event.ForgeEventFactory.onHoeUse(context);
// if (hook != 0) return hook > 0 ? InteractionResult.SUCCESS : InteractionResult.FAIL;
if (context.getClickedFace() != Direction.DOWN && world.isEmptyBlock(blockpos.above()) && (block1 instanceof GrassBlock
|| block1.equals(Blocks.DIRT) || block1.equals(Blocks.COARSE_DIRT))) {
var blockstate = Blocks.FARMLAND.defaultBlockState().setValue(FarmBlock.MOISTURE, 7);
var playerentity = context.getPlayer();
world.playSound(playerentity, blockpos, SoundEvents.HOE_TILL, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide && playerentity != null) {
int rang = 5;
var minPos = blockpos.offset(-rang, 0, -rang);
var maxPos = blockpos.offset(rang, 0, rang);
if (playerentity.isCrouching()) {
if (context.getClickedFace() != Direction.DOWN && world.isEmptyBlock(blockpos.above()) &&
(targetBlock instanceof GrassBlock || targetBlock.equals(Blocks.DIRT) || targetBlock.equals(Blocks.COARSE_DIRT))) {
if (player != null && !world.isClientSide) {
if (stack.getOrCreateTag().getBoolean("sow")) {
var boxMutable = BlockPos.betweenClosed(minPos, maxPos);
for (BlockPos pos : boxMutable) {
var state = world.getBlockState(pos);
Expand All @@ -160,7 +172,6 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
}
}


Iterable<BlockPos> inBoxMutable = BlockPos.betweenClosed(minPos, maxPos.offset(0, 3, 0));
Iterable<BlockPos> allInBoxMutable = BlockPos.betweenClosed(minPos.offset(-1, 0, -1), maxPos.offset(1, 4, 1));
for (BlockPos pos : allInBoxMutable) {
Expand All @@ -172,6 +183,7 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
}
} else world.setBlock(blockpos, blockstate, 11); //未潜行耕种一个方块
}
world.playSound(player, blockpos, SoundEvents.HOE_TILL, SoundSource.BLOCKS, 1.0F, 1.0F);
return InteractionResult.sidedSuccess(world.isClientSide);
}
return InteractionResult.PASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import committee.nova.mods.avaritia.util.ToolUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
Expand Down Expand Up @@ -84,6 +86,9 @@ public float getDestroySpeed(ItemStack stack, @NotNull BlockState state) {
CompoundTag tags = stack.getOrCreateTag();
tags.putBoolean("hammer", !tags.getBoolean("hammer"));
player.swing(hand);
if(!world.isClientSide && player instanceof ServerPlayer serverPlayer) serverPlayer.sendSystemMessage(
Component.translatable(tags.getBoolean("hammer") ? "tooltip.infinity_pickaxe.type_2" : "tooltip.infinity_pickaxe.type_1"
), true);
return InteractionResultHolder.success(stack);
}
return super.use(world, player, hand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import committee.nova.mods.avaritia.util.ToolUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -74,6 +76,9 @@ public float getDestroySpeed(ItemStack stack, @NotNull BlockState state) {
CompoundTag tags = stack.getOrCreateTag();
tags.putBoolean("destroyer", !tags.getBoolean("destroyer"));
player.swing(hand);
if(!pLevel.isClientSide && player instanceof ServerPlayer serverPlayer) serverPlayer.sendSystemMessage(
Component.translatable(tags.getBoolean("destroyer") ? "tooltip.infinity_shovel.type_2" : "tooltip.infinity_shovel.type_1"
), true);
return InteractionResultHolder.success(stack);
}
return super.use(pLevel, player, hand);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package committee.nova.mods.avaritia.init.compat.projecte;

import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.init.config.ModConfig;
import committee.nova.mods.avaritia.init.registry.ModItems;
import moze_intel.projecte.api.imc.CustomEMCRegistration;
import moze_intel.projecte.api.nss.NSSItem;
Expand All @@ -19,7 +20,7 @@ private static void registerEMC(ItemLike item, int emc) {
APICustomEMCMapper.INSTANCE.registerCustomEMC(Static.MOD_ID, new CustomEMCRegistration(NSSItem.createItem(item), emc));
}
public static void init() {
registerEMC(ModItems.neutron_pile.get(), 100);
registerEMC(Items.TOTEM_OF_UNDYING, 1000);
registerEMC(ModItems.neutron_pile.get(), ModConfig.neutronPileEmc.get());
registerEMC(Items.TOTEM_OF_UNDYING, ModConfig.vanillaTotemEmc.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ public class ModConfig {
public static final ForgeConfigSpec.IntValue neutronCollectorProductTick;
public static final ForgeConfigSpec.IntValue singularityTimeRequired;

public static final ForgeConfigSpec.IntValue neutronPileEmc;
public static final ForgeConfigSpec.IntValue vanillaTotemEmc;

//SERVER
static {
final var common = new ForgeConfigSpec.Builder();
common.comment("Avaritia Base Config").push("general");
common.comment("Avaritia Config");
common.push("tools");
isKeepStone = buildBoolean(common, "Is Stone", false, "Does the super mode of endless tools retain stone and soil");
isMergeMatterCluster = buildBoolean(common, "Is Merge Matter Cluster", false, "Whether to merge matter cluster");
isMergeMatterCluster = buildBoolean(common, "Is Merge Matter Cluster", true, "Whether to merge matter cluster");
swordRangeDamage = buildInt(common, "Sword Range Damage", 10000, 100, 100000, "Range damage value of the right key of Infinity sword");
swordAttackRange = buildInt(common, "Sword Attack Range", 32, 8, 64, "Infinity sword right click attack range");
isSwordAttackAnimal = buildBoolean(common, "Is Sword Damage Animal", false, "Does the right key range attack of endless sword attack neutral creatures");
Expand All @@ -45,6 +49,11 @@ public class ModConfig {
neutronCollectorProductTick = buildInt(common, "Neutron Collector Product Tick", 3600, 1200, Integer.MAX_VALUE, "The product tick of NeutronCollector");
singularityTimeRequired = buildInt(common, "Singularity Time Required", 240, 0, Integer.MAX_VALUE, "Singularity default time required");
common.pop();
common.push("emc");
neutronPileEmc = buildInt(common, "Neutron Pile Emc", 100, 0, Integer.MAX_VALUE, "Emc of Neutron Pile");
vanillaTotemEmc = buildInt(common, "Vanilla Totem Emc", 1000, 0, Integer.MAX_VALUE, "Emc of Totem Of Undying");
common.pop();

COMMON = common.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import committee.nova.mods.avaritia.common.item.MatterClusterItem;
import committee.nova.mods.avaritia.common.item.tools.infinity.*;
import committee.nova.mods.avaritia.common.net.S2CTotemPacket;
import committee.nova.mods.avaritia.init.config.ModConfig;
import committee.nova.mods.avaritia.init.registry.ModDamageTypes;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.util.ToolUtils;
Expand All @@ -21,6 +22,8 @@
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.AbstractSkeleton;
import net.minecraft.world.entity.monster.Skeleton;
import net.minecraft.world.entity.monster.WitherSkeleton;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -152,7 +155,7 @@ public static void canHarvest(PlayerEvent.HarvestCheck event) {
//合并物质团
@SubscribeEvent
public static void clusterCluster(EntityItemPickupEvent event) {
if (event.getEntity() != null && event.getItem().getItem().is(ModItems.matter_cluster.get())) {
if (event.getEntity() != null && ModConfig.isMergeMatterCluster.get() && event.getItem().getItem().is(ModItems.matter_cluster.get())) {
ItemStack stack = event.getItem().getItem();
boolean mergedAny = false;
Player player = event.getEntity();
Expand Down Expand Up @@ -265,7 +268,7 @@ public static void onAttacked(LivingAttackEvent event) {
@SubscribeEvent
public static void onLivingDrops(LivingDropsEvent event) {
if (event.isRecentlyHit() &&
event.getEntity() instanceof WitherSkeleton witherSkeleton
event.getEntity() instanceof AbstractSkeleton
&& event.getSource().getEntity() instanceof Player player
) {
if (player.getMainHandItem().is(ModItems.skull_sword.get()) || player.getOffhandItem().is(ModItems.skull_sword.get())) {
Expand Down
Loading

0 comments on commit 712bf18

Please sign in to comment.