Skip to content

Commit

Permalink
refactor(1.20.1-forged): axe
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Jul 26, 2024
1 parent db05257 commit 566c28a
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import committee.nova.mods.avaritia.Static;
import committee.nova.mods.avaritia.client.shader.AvaritiaShaders;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.util.AbilityUtils;
import committee.nova.mods.avaritia.util.ToolUtils;
import committee.nova.mods.avaritia.util.client.ColorUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
Expand All @@ -22,7 +21,6 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.Material;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
Expand Down Expand Up @@ -309,7 +307,7 @@ public PlayerRender(final RenderLayerParent<Player, PlayerModel<Player>> t) {

@Override
public void render(final @NotNull PoseStack pPoseStack, final @NotNull MultiBufferSource pBuffer, final int pPackedLight, final @NotNull Player l, final float pLimbSwing, float pLimbSwingAmount, float pPartialTick, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch) {
if (AbilityUtils.isInfinite(l)) {
if (ToolUtils.isInfinite(l)) {
AvaritiaShaders.cosmicOpacity.set(2.0f);
this.playerParts().forEach(t -> t.render(pPoseStack, InfinityArmorModel.material(MASK_INV).buffer(pBuffer, InfinityArmorModel::mask2), pPackedLight, 1, 1.0f, 1.0f, 1.0f, 1.0f));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static committee.nova.mods.avaritia.util.ToolUtils.canHarvest;
import static committee.nova.mods.avaritia.util.ToolUtils.destroyTree;

/**
* Description:
* Author: cnlimiter
Expand Down Expand Up @@ -74,8 +77,11 @@ public int getEnchantmentValue(ItemStack stack) {

@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
if (player.isCrouching() && !player.level().isClientSide) {
ToolUtils.breakRangeBlocks(player, stack, pos, 13, ToolUtils.materialsAxe, true);
Level world = player.level();
if (!world.isClientSide ) {
if (player.isCrouching() && canHarvest(pos, world)) {
destroyTree(player, world, pos, stack);
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import committee.nova.mods.avaritia.init.registry.ModEntities;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.init.registry.ModTiers;
import committee.nova.mods.avaritia.util.ClustersUtils;
import committee.nova.mods.avaritia.util.ItemUtils;
import committee.nova.mods.avaritia.util.ToolUtils;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
Expand Down Expand Up @@ -88,23 +88,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) {
ToolUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
pLevel.setBlock(pos, state.setValue(block instanceof BeetrootBlock ? BeetrootBlock.AGE : CropBlock.AGE, 0), 11);
}
}
if (block instanceof CocoaBlock) { //coca
if (state.getValue(CocoaBlock.AGE) >= 2) {
ToolUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
pLevel.setBlock(pos, state.setValue(CocoaBlock.AGE, 0), 11);
}
}
if (block instanceof StemGrownBlock) { //pumpkin
ToolUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
pLevel.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
}
if (block instanceof SweetBerryBushBlock) { //SweetBerry
if (state.getValue(SweetBerryBushBlock.AGE) >= 3) {
ToolUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
ClustersUtils.putMapDrops(pLevel, pos, pPlayer, new ItemStack(this), map);
pLevel.setBlock(pos, state.setValue(SweetBerryBushBlock.AGE, 0), 11);
}
}
Expand All @@ -116,7 +116,7 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
}
ItemCaptureHandler.enableItemCapture(false);
Set<ItemStack> drops = ItemCaptureHandler.getCapturedDrops();
ToolUtils.spawnClusters(pLevel, pPlayer, map.keySet());
ClustersUtils.spawnClusters(pLevel, pPlayer, map.keySet());
pPlayer.getCooldowns().addCooldown(heldItem.getItem(), 20);
}
pLevel.playSound(pPlayer, pPlayer.getOnPos(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1.0f, 5.0f);
Expand Down Expand Up @@ -166,7 +166,7 @@ public float getDestroySpeed(@NotNull ItemStack stack, @NotNull BlockState state
}
ItemCaptureHandler.enableItemCapture(false);
Set<ItemStack> drops = ItemCaptureHandler.getCapturedDrops();
ToolUtils.spawnClusters(world, playerentity, map.keySet());
ClustersUtils.spawnClusters(world, playerentity, map.keySet());

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));
Expand Down Expand Up @@ -204,7 +204,7 @@ private void harvest(Level world, BlockPos pos, Player player, Map<ItemStack, In
if (!itemStack.isEmpty())
map.put(itemStack, map.get(itemStack) + stack1.getCount());
else map.put(stack1, stack1.getCount());
} else ToolUtils.putMapDrops(world, pos, player, new ItemStack(this), map);
} else ClustersUtils.putMapDrops(world, pos, player, new ItemStack(this), map);
world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import committee.nova.mods.avaritia.init.registry.ModEntities;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.init.registry.ModTiers;
import committee.nova.mods.avaritia.util.AbilityUtils;
import committee.nova.mods.avaritia.util.ToolUtils;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -62,7 +62,7 @@ public boolean hurtEnemy(@NotNull ItemStack stack, @NotNull LivingEntity victim,
dragon.hurt(dragon.head, player.damageSources().source(ModDamageTypes.INFINITY, player, victim), Float.POSITIVE_INFINITY);
dragon.setHealth(0);//fix
} else if (victim instanceof Player pvp) {
if (AbilityUtils.isInfinite(pvp)) {
if (ToolUtils.isInfinite(pvp)) {
victim.hurt(livingEntity.damageSources().source(ModDamageTypes.INFINITY, livingEntity, victim), 4.0F);
} else
victim.hurt(livingEntity.damageSources().source(ModDamageTypes.INFINITY, livingEntity, victim), Float.POSITIVE_INFINITY);
Expand All @@ -73,12 +73,12 @@ public boolean hurtEnemy(@NotNull ItemStack stack, @NotNull LivingEntity victim,
victim.lastHurtByPlayerTime = 60;
victim.getCombatTracker().recordDamage(livingEntity.damageSources().source(ModDamageTypes.INFINITY, livingEntity, victim), victim.getHealth());

if(victim instanceof Player victimP && AbilityUtils.isInfinite(victimP)) {
if(victim instanceof Player victimP && ToolUtils.isInfinite(victimP)) {
victimP.level().explode(livingEntity, victimP.getBlockX(), victimP.getBlockY(), victimP.getBlockZ(), 25.0f, Level.ExplosionInteraction.BLOCK);
// 玩家身着无尽甲则只造成爆炸伤害
return true;
}
AbilityUtils.sweepAttack(level, livingEntity, victim);
ToolUtils.sweepAttack(level, livingEntity, victim);

victim.setHealth(0);
victim.die(livingEntity.damageSources().source(ModDamageTypes.INFINITY, livingEntity, victim));
Expand All @@ -90,7 +90,7 @@ public boolean hurtEnemy(@NotNull ItemStack stack, @NotNull LivingEntity victim,
public @NotNull InteractionResultHolder<ItemStack> use(Level level, Player player, @NotNull InteractionHand hand) {
var heldItem = player.getItemInHand(hand);
if (!level.isClientSide) {
AbilityUtils.attackAOE(player, ModConfig.swordAttackRange.get(), ModConfig.swordRangeDamage.get(), ModConfig.isSwordAttackAnimal.get(), ModConfig.isSwordAttackLightning.get());
ToolUtils.aoeAttack(player, ModConfig.swordAttackRange.get(), ModConfig.swordRangeDamage.get(), ModConfig.isSwordAttackAnimal.get(), ModConfig.isSwordAttackLightning.get());
player.getCooldowns().addCooldown(heldItem.getItem(), 20);
}
level.playSound(player, player.getOnPos(), SoundEvents.PLAYER_LEVELUP, SoundSource.PLAYERS, 1.0f, 5.0f);
Expand All @@ -102,7 +102,7 @@ public boolean hurtEnemy(@NotNull ItemStack stack, @NotNull LivingEntity victim,
@Override
public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) {
if (!entity.level().isClientSide && entity instanceof Player victim) {
if (!victim.isCreative() && !victim.isDeadOrDying() && victim.getHealth() > 0 && !AbilityUtils.isInfinite(victim)) {
if (!victim.isCreative() && !victim.isDeadOrDying() && victim.getHealth() > 0 && !ToolUtils.isInfinite(victim)) {
victim.getCombatTracker().recordDamage(player.damageSources().source(ModDamageTypes.INFINITY, player, victim), victim.getHealth());
victim.setHealth(0);
victim.die(player.damageSources().source(ModDamageTypes.INFINITY, player, victim));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.*;

import static committee.nova.mods.avaritia.util.AbilityUtils.isPlayerWearing;
import static committee.nova.mods.avaritia.util.ToolUtils.isPlayerWearing;
import static net.minecraft.world.entity.EquipmentSlot.*;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import committee.nova.mods.avaritia.common.net.S2CTotemPacket;
import committee.nova.mods.avaritia.init.registry.ModDamageTypes;
import committee.nova.mods.avaritia.init.registry.ModItems;
import committee.nova.mods.avaritia.util.AbilityUtils;
import committee.nova.mods.avaritia.util.ToolUtils;
import committee.nova.mods.avaritia.util.lang.TextUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.resources.language.I18n;
Expand Down Expand Up @@ -207,7 +207,7 @@ public static void onTooltip(ItemTooltipEvent event) {
@SubscribeEvent
public static void onDeath(LivingDeathEvent event) {
if (event.getEntity() instanceof ServerPlayer player) {
if (AbilityUtils.isInfinite(player) && !(event.getSource() instanceof ModDamageTypes.DamageSourceRandomMessages)) {
if (ToolUtils.isInfinite(player) && !(event.getSource() instanceof ModDamageTypes.DamageSourceRandomMessages)) {
event.setCanceled(true);
player.setHealth(player.getMaxHealth());
}
Expand All @@ -221,7 +221,7 @@ public static void onDeath(LivingDeathEvent event) {
player.setHealth(player.getMaxHealth());
player.addEffect(new MobEffectInstance(MobEffects.JUMP, 800, 1));
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 800, 1));
AbilityUtils.attackAOE(player, 8, 1000.0f, false, false);//触发无尽图腾后对附近造成伤害
ToolUtils.aoeAttack(player, 8, 1000.0f, false, false);//触发无尽图腾后对附近造成伤害
player.displayClientMessage(Component.translatable("tooltip.avaritia.totem_break"), false);
}else {
player.setHealth(10.0F);
Expand All @@ -245,7 +245,7 @@ public static void onGetHurt(LivingHurtEvent event) {
if (!player.getMainHandItem().isEmpty() && player.getMainHandItem().is(ModItems.infinity_sword.get()) && player.getMainHandItem().useOnRelease()) {
event.setCanceled(true);
}
if (AbilityUtils.isInfinite(player) && !event.getSource().is(ModDamageTypes.INFINITY)) {
if (ToolUtils.isInfinite(player) && !event.getSource().is(ModDamageTypes.INFINITY)) {
event.setCanceled(true);
}
}
Expand All @@ -256,7 +256,7 @@ public static void onAttacked(LivingAttackEvent event) {
if (!(event.getEntity() instanceof Player player)) {
return;
}
if (AbilityUtils.isInfinite(player) && !event.getSource().is(ModDamageTypes.INFINITY)) {
if (ToolUtils.isInfinite(player) && !event.getSource().is(ModDamageTypes.INFINITY)) {
event.setCanceled(true);
}
}
Expand Down
98 changes: 0 additions & 98 deletions src/main/java/committee/nova/mods/avaritia/util/AbilityUtils.java

This file was deleted.

Loading

0 comments on commit 566c28a

Please sign in to comment.