Skip to content

Commit

Permalink
Merge pull request #1441 from YocyCraft/dev/misc_optimize
Browse files Browse the repository at this point in the history
Fix several issues for Giant Anvil 修复巨型铁砧的相关问题
  • Loading branch information
Gu-ZT authored Jan 1, 2025
2 parents 9f64313 + a40b86a commit 70dd576
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 140 deletions.
2 changes: 2 additions & 0 deletions src/generated/resources/assets/anvilcraft/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@
"text.autoconfig.anvilcraft.option.geodeInterval.@Tooltip": "ǝpoǝb ǝɥʇ ɟo ןɐʌɹǝʇuı ɥɔɹɐǝs ǝɥ⟘",
"text.autoconfig.anvilcraft.option.geodeRadius": "snıpɐᴚ ɥɔɹɐǝS ɯnɯıxɐW ǝpoǝ⅁",
"text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "ǝpoǝb ǝɥʇ ɟo snıpɐɹ ɥɔɹɐǝs ɯnɯıxɐɯ ǝɥ⟘",
"text.autoconfig.anvilcraft.option.giantAnvilMaxShockRadius": "snıpɐᴚ ʞɔoɥS xɐW ןıʌuⱯ ʇuɐı⅁",
"text.autoconfig.anvilcraft.option.giantAnvilMaxShockRadius.@Tooltip": "ɹoıʌɐɥǝq ʞɔoɥs s,ןıʌuɐ ʇuɐıb ɟo snıpɐɹ ɯnɯıxɐW",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval": "ןɐʌɹǝʇuı uoıʇɔǝʇǝp sʇɐʇsoıןǝH",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval.@Tooltip": "suoıʇɔǝʇǝp ʇɐʇsoıןǝɥ uǝǝʍʇǝq sʞɔıʇ ɟo ɹǝqɯnu ǝɥ⟘",
"text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "uʍopןooƆ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/anvilcraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@
"text.autoconfig.anvilcraft.option.geodeInterval.@Tooltip": "The search interval of the geode",
"text.autoconfig.anvilcraft.option.geodeRadius": "Geode Maximum Search Radius",
"text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "The maximum search radius of the geode",
"text.autoconfig.anvilcraft.option.giantAnvilMaxShockRadius": "Giant Anvil Max Shock Radius",
"text.autoconfig.anvilcraft.option.giantAnvilMaxShockRadius.@Tooltip": "Maximum radius of giant anvil's shock behavior",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval": "Heliostats detection interval",
"text.autoconfig.anvilcraft.option.heliostatsDetectionInterval.@Tooltip": "The number of ticks between heliostat detections",
"text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "Induction Light Block Ripening Cooldown",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class AnvilCraftConfig implements ConfigData {
@ConfigEntry.BoundedDiscrete(max = 64, min = 1)
public int anvilEfficiency = 64;

@Comment("Maximum radius of giant anvil's shock behavior")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 16, min = 4)
public int giantAnvilMaxShockRadius = 16;

@Comment("Maximum depth a lightning strike can reach")
@ConfigEntry.Gui.Tooltip
@ConfigEntry.BoundedDiscrete(max = 16, min = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,31 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.DirectionalPlaceContext;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ConcretePowderBlock;
import net.minecraft.world.level.block.FallingBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

import org.jetbrains.annotations.NotNull;

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
public class FallingGiantAnvilEntity extends FallingBlockEntity {

private float fallDistance = 0;
Expand All @@ -51,6 +50,18 @@ private FallingGiantAnvilEntity(Level level, double x, double y, double z, Block
this.setStartPos(this.blockPosition());
}

@Override
protected void addAdditionalSaveData(CompoundTag data) {
super.addAdditionalSaveData(data);
data.putFloat("anvilcraft$FallDistance", this.fallDistance);
}

@Override
protected void readAdditionalSaveData(CompoundTag data) {
super.readAdditionalSaveData(data);
this.fallDistance = data.getFloat("anvilcraft$fallDistance");
}

/**
* @param level 世界
* @param pos 方块坐标
Expand Down Expand Up @@ -91,28 +102,8 @@ public void tick() {
}
if (!this.level().isClientSide) {
BlockPos blockPos = this.blockPosition();
boolean isConcrete = this.blockState.getBlock() instanceof ConcretePowderBlock;
boolean shouldHandleWater =
isConcrete && this.level().getFluidState(blockPos).is(FluidTags.WATER);
double d = this.getDeltaMovement().lengthSqr();
if (isConcrete && d > 1.0) {
BlockHitResult blockHitResult = this.level()
.clip(new ClipContext(
new Vec3(this.xo, this.yo, this.zo),
this.position(),
net.minecraft.world.level.ClipContext.Block.COLLIDER,
ClipContext.Fluid.SOURCE_ONLY,
this));
if (blockHitResult.getType() != HitResult.Type.MISS
&& this.level()
.getFluidState(blockHitResult.getBlockPos())
.is(FluidTags.WATER)) {
blockPos = blockHitResult.getBlockPos();
shouldHandleWater = true;
}
}
Block block = this.blockState.getBlock();
if (!this.onGround() && !shouldHandleWater) {
if (!this.onGround()) {
if (!this.level().isClientSide
&& (this.time > 100
&& (blockPos.getY() <= this.level().getMinBuildHeight()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
import dev.dubhe.anvilcraft.recipe.anvil.BlockCrushRecipe;
import dev.dubhe.anvilcraft.recipe.anvil.ItemInjectRecipe;
import dev.dubhe.anvilcraft.recipe.anvil.SqueezingRecipe;

import dev.dubhe.anvilcraft.util.BreakBlockUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
Expand All @@ -25,18 +22,12 @@
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.SingleRecipeInput;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LayeredCauldronBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.LootTable;
Expand All @@ -45,13 +36,13 @@
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.neoforged.bus.api.SubscribeEvent;

import net.neoforged.fml.common.EventBusSubscriber;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static dev.dubhe.anvilcraft.util.AnvilUtil.dropItems;
Expand Down Expand Up @@ -181,38 +172,26 @@ private static void brokeBlock(@NotNull Level level, BlockPos pos, AnvilFallOnLa
BlockState state = level.getBlockState(pos);
if (state.getBlock().getExplosionResistance() >= 1200.0) event.setAnvilDamage(true);
if (state.getDestroySpeed(level, pos) < 0) return;
BlockEntity blockEntity = state.hasBlockEntity() ? level.getBlockEntity(pos) : null;
LootParams.Builder builder = new LootParams.Builder(serverLevel)
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity);
state.spawnAfterBreak(serverLevel, pos, ItemStack.EMPTY, false);
boolean smeltDrop = Optional.ofNullable(event.getEntity())
.map(FallingBlockEntity::getBlockState)
.map(b -> b.getBlock() instanceof EmberAnvilBlock)
.orElse(false);
boolean silkTouch = Optional.ofNullable(event.getEntity())
.map(FallingBlockEntity::getBlockState)
.map(b -> b.getBlock() instanceof RoyalAnvilBlock)
.orElse(false);
ItemStack dummyTool = silkTouch ? BreakBlockUtil.getDummySilkTouchTool(serverLevel) : ItemStack.EMPTY;
state.spawnAfterBreak(serverLevel, pos, dummyTool, false);
if (state.getBlock() instanceof IHasMultiBlock multiBlock) {
multiBlock.onRemove(level, pos, state);
}
List<ItemStack> drops = state.getDrops(builder);
if (event.getEntity() != null && event.getEntity().blockState.getBlock() instanceof EmberAnvilBlock) {
drops = drops.stream()
.map(it -> {
SingleRecipeInput cont = new SingleRecipeInput(it);
return level.getRecipeManager()
.getRecipeFor(RecipeType.SMELTING, cont, level)
.map(smeltingRecipe -> smeltingRecipe.value().assemble(cont, level.registryAccess()))
.orElse(it);
})
.collect(Collectors.toList());
List<ItemStack> drops;
if (smeltDrop) {
drops = BreakBlockUtil.dropSmelt(serverLevel, pos);
} else if (silkTouch) {
drops = BreakBlockUtil.dropSilkTouch(serverLevel, pos);
} else {
if (event.getEntity() != null && event.getEntity().blockState.getBlock() instanceof RoyalAnvilBlock) {
HolderLookup<Enchantment> holderLookup = level.holderLookup(Registries.ENCHANTMENT);
Holder<Enchantment> silkTouchEnchantment = holderLookup.get(Enchantments.SILK_TOUCH).orElseThrow();
ItemStack tool = Items.NETHERITE_PICKAXE.getDefaultInstance();
tool.enchant(silkTouchEnchantment, 1);
builder.withParameter(
LootContextParams.TOOL,
tool
);
drops = state.getDrops(builder);
}
drops = BreakBlockUtil.drop(serverLevel, pos);
}
dropItems(drops, level, pos.getCenter());
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
Expand Down
Loading

0 comments on commit 70dd576

Please sign in to comment.