Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block update behavior of giant anvil and add Mekanism Integration 修复巨型铁砧的方块更新,增加通用机械联动 #1401

Merged
merged 8 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"values": [
"anvilcraft:giant_anvil",
"anvilcraft:transmission_pole",
"anvilcraft:remote_transmission_pole",
"anvilcraft:tesla_tower",
"anvilcraft:overseer"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;

import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -116,9 +115,7 @@ private void preventCreativeDropFromMainPart(
BlockState mainPartState = level.getBlockState(mainPartPos);
if (!mainPartState.is(this)) return;
if (!mainPartState.hasProperty(this.getPart())) return;
BlockState blockState2 = mainPartState.getFluidState().is(Fluids.WATER)
? Blocks.WATER.defaultBlockState()
: Blocks.AIR.defaultBlockState();
BlockState blockState2 = mainPartState.getFluidState().createLegacyBlock();
level.setBlock(mainPartPos, blockState2, 35);
level.levelEvent(player, 2001, mainPartPos, Block.getId(mainPartState));
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/block/BlockComparatorBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.serialization.MapCodec;
import dev.dubhe.anvilcraft.api.hammer.HammerRotateBehavior;
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -25,8 +26,12 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class BlockComparatorBlock extends HorizontalDirectionalBlock implements HammerRotateBehavior, IHammerRemovable {

public static final MapCodec<BlockComparatorBlock> CODEC = simpleCodec(BlockComparatorBlock::new);
Expand Down Expand Up @@ -152,6 +157,11 @@ protected void updateNeighborsInFront(Level level, BlockPos pos, BlockState stat
level.updateNeighborsAtExceptFromFacing(blockpos, this, direction);
}

@Override
public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos pos, @Nullable Direction direction) {
return direction == state.getValue(FACING);
}

@Override
protected boolean isSignalSource(BlockState state) {
return true;
Expand Down
93 changes: 90 additions & 3 deletions src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.dubhe.anvilcraft.block;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import dev.dubhe.anvilcraft.api.event.anvil.AnvilFallOnLandEvent;
import dev.dubhe.anvilcraft.api.event.anvil.GiantAnvilFallOnLandEvent;
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import dev.dubhe.anvilcraft.block.state.Cube3x3PartHalf;
import dev.dubhe.anvilcraft.block.state.GiantAnvilCube;
import dev.dubhe.anvilcraft.entity.FallingGiantAnvilEntity;
import dev.dubhe.anvilcraft.init.ModBlocks;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -43,10 +44,8 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

import net.neoforged.neoforge.common.NeoForge;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.stream.Stream;

Expand Down Expand Up @@ -113,6 +112,81 @@ public class GiantAnvilBlock extends AbstractMultiplePartBlock<Cube3x3PartHalf>
.reduce((v1, v2) -> Shapes.join(v1, v2, BooleanOp.OR))
.get();

private static final ImmutableMap<Direction, ImmutableList<Vec3i>> UPDATE_OFFSET = ImmutableMap.of(
Direction.DOWN,
ImmutableList.of(
new Vec3i(-1, 3, -1),
new Vec3i(-1, 3, 0),
new Vec3i(-1, 3, 1),
new Vec3i(0, 3, -1),
new Vec3i(0, 3, 0),
new Vec3i(0, 3, 1),
new Vec3i(1, 3, -1),
new Vec3i(1, 3, 0),
new Vec3i(1, 3, 1)
),
Direction.UP,
ImmutableList.of(
new Vec3i(-1, -1, -1),
new Vec3i(-1, -1, 0),
new Vec3i(-1, -1, 1),
new Vec3i(0, -1, -1),
new Vec3i(0, -1, 0),
new Vec3i(0, -1, 1),
new Vec3i(1, -1, -1),
new Vec3i(1, -1, 0),
new Vec3i(1, -1, 1)
),
Direction.EAST,
ImmutableList.of(
new Vec3i(-2, 0, -1),
new Vec3i(-2, 0, 0),
new Vec3i(-2, 0, 1),
new Vec3i(-2, 1, -1),
new Vec3i(-2, 1, 0),
new Vec3i(-2, 1, 1),
new Vec3i(-2, 2, -1),
new Vec3i(-2, 2, 0),
new Vec3i(-2, 2, 1)
),
Direction.WEST,
ImmutableList.of(
new Vec3i(2, 0, -1),
new Vec3i(2, 0, 0),
new Vec3i(2, 0, 1),
new Vec3i(2, 1, -1),
new Vec3i(2, 1, 0),
new Vec3i(2, 1, 1),
new Vec3i(2, 2, -1),
new Vec3i(2, 2, 0),
new Vec3i(2, 2, 1)
),
Direction.SOUTH,
ImmutableList.of(
new Vec3i(-1, 0, -2),
new Vec3i(0, 0, -2),
new Vec3i(1, 0, -2),
new Vec3i(-1, 1, -2),
new Vec3i(0, 1, -2),
new Vec3i(1, 1, -2),
new Vec3i(-1, 2, -2),
new Vec3i(0, 2, -2),
new Vec3i(1, 2, -2)
),
Direction.NORTH,
ImmutableList.of(
new Vec3i(-1, 0, 2),
new Vec3i(0, 0, 2),
new Vec3i(1, 0, 2),
new Vec3i(-1, 1, 2),
new Vec3i(0, 1, 2),
new Vec3i(1, 1, 2),
new Vec3i(-1, 2, 2),
new Vec3i(0, 2, 2),
new Vec3i(1, 2, 2)
)
);

/**
* @param properties 属性
*/
Expand Down Expand Up @@ -249,6 +323,19 @@ public void tick(
}
}
}

UPDATE_OFFSET.forEach((direction, offestList) -> offestList.forEach(offset -> {
BlockPos updatedPos = pos.offset(offset);
BlockPos fromPos = updatedPos.relative(direction);
level.neighborShapeChanged(direction,
level.getBlockState(fromPos),
updatedPos,
fromPos,
3,
512
);
}));

FallingBlockEntity fallingBlockEntity = FallingGiantAnvilEntity.fall(level, above, state1, false);
this.falling(fallingBlockEntity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.mojang.logging.LogUtils;
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.integration.iris.IrisState;
import dev.dubhe.anvilcraft.util.Util;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.neoforged.fml.ModList;
import org.slf4j.Logger;

public class RenderState {
Expand All @@ -15,7 +15,7 @@ public class RenderState {
private static final Logger logger = LogUtils.getLogger();

static {
IRIS_PRESENT = ModList.get().isLoaded("iris");
IRIS_PRESENT = Util.isLoaded("iris");
}

public static boolean isIrisPresent() {
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/dev/dubhe/anvilcraft/data/tags/BlockTagLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ public static void init(@NotNull RegistrateTagsProvider<Block> provider) {
.add(findResourceKey(Blocks.ANVIL))
.add(findResourceKey(Blocks.CHIPPED_ANVIL))
.add(findResourceKey(Blocks.DAMAGED_ANVIL))
.add(findResourceKey(ModBlocks.HEAVY_IRON_BLOCK.get()))
.add(findResourceKey(ModBlocks.HEAVY_IRON_BEAM.get()))
.add(findResourceKey(ModBlocks.HEAVY_IRON_COLUMN.get()))
.add(findResourceKey(ModBlocks.HEAVY_IRON_PLATE.get()))
.add(findResourceKey(ModBlocks.CUT_HEAVY_IRON_BLOCK.get()))
.add(findResourceKey(ModBlocks.CUT_HEAVY_IRON_SLAB.get()))
.add(findResourceKey(ModBlocks.CUT_HEAVY_IRON_STAIRS.get()))
.add(findResourceKey(ModBlocks.POLISHED_HEAVY_IRON_BLOCK.get()))
.add(findResourceKey(ModBlocks.POLISHED_HEAVY_IRON_SLAB.get()))
.add(findResourceKey(ModBlocks.POLISHED_HEAVY_IRON_STAIRS.get()));
.add(ModBlocks.HEAVY_IRON_BLOCK.getKey())
.add(ModBlocks.HEAVY_IRON_BEAM.getKey())
.add(ModBlocks.HEAVY_IRON_COLUMN.getKey())
.add(ModBlocks.HEAVY_IRON_PLATE.getKey())
.add(ModBlocks.CUT_HEAVY_IRON_BLOCK.getKey())
.add(ModBlocks.CUT_HEAVY_IRON_SLAB.getKey())
.add(ModBlocks.CUT_HEAVY_IRON_STAIRS.getKey())
.add(ModBlocks.POLISHED_HEAVY_IRON_BLOCK.getKey())
.add(ModBlocks.POLISHED_HEAVY_IRON_SLAB.getKey())
.add(ModBlocks.POLISHED_HEAVY_IRON_STAIRS.getKey());

provider.addTag(ModBlockTags.UNDER_CAULDRON)
.addTag(BlockTags.CAMPFIRES)
.add(findResourceKey(Blocks.MAGMA_BLOCK))
.add(findResourceKey(ModBlocks.HEATER.get()))
.add(findResourceKey(ModBlocks.CORRUPTED_BEACON.get()));
.add(ModBlocks.HEATER.getKey())
.add(ModBlocks.CORRUPTED_BEACON.getKey());

provider.addTag(ModBlockTags.BLOCK_DEVOURER_PROBABILITY_DROPPING)
.add(findResourceKey(Blocks.STONE))
Expand Down Expand Up @@ -132,7 +132,14 @@ public static void init(@NotNull RegistrateTagsProvider<Block> provider) {
provider.addTag(ModBlockTags.NEUTRONIUM_CANNOT_PASS_THROUGH)
.add(findResourceKey(Blocks.END_STONE))
.add(findResourceKey(Blocks.BEDROCK))
.add(findResourceKey(ModBlocks.END_DUST.get()))
.add(findResourceKey(ModBlocks.NEGATIVE_MATTER_BLOCK.get()));
.add(ModBlocks.END_DUST.getKey())
.add(ModBlocks.NEGATIVE_MATTER_BLOCK.getKey());

provider.addTag(ModBlockTags.MEKANISM_CARDBOARD_BOX_BLACKLIST)
.add(ModBlocks.GIANT_ANVIL.getKey())
.add(ModBlocks.TRANSMISSION_POLE.getKey())
.add(ModBlocks.REMOTE_TRANSMISSION_POLE.getKey())
.add(ModBlocks.TESLA_TOWER.getKey())
.add(ModBlocks.OVERSEER_BLOCK.getKey());
}
}
34 changes: 17 additions & 17 deletions src/main/java/dev/dubhe/anvilcraft/data/tags/ItemTagLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,52 @@ public static void init(@NotNull RegistrateTagsProvider<Item> provider) {
provider.addTag(ModItemTags.GOLD_PLATES).add(findResourceKey(Items.LIGHT_WEIGHTED_PRESSURE_PLATE));

provider.addTag(ModItemTags.ROYAL_STEEL_PICKAXE_BASE)
.add(findResourceKey(ModItems.AMETHYST_PICKAXE.get()))
.add(ModItems.AMETHYST_PICKAXE.getKey())
.add(findResourceKey(Items.GOLDEN_PICKAXE))
.add(findResourceKey(Items.IRON_PICKAXE))
.add(findResourceKey(Items.DIAMOND_PICKAXE));
provider.addTag(ModItemTags.ROYAL_STEEL_AXE_BASE)
.add(findResourceKey(ModItems.AMETHYST_AXE.get()))
.add(ModItems.AMETHYST_AXE.getKey())
.add(findResourceKey(Items.GOLDEN_AXE))
.add(findResourceKey(Items.IRON_AXE))
.add(findResourceKey(Items.DIAMOND_AXE));
provider.addTag(ModItemTags.ROYAL_STEEL_HOE_BASE)
.add(findResourceKey(ModItems.AMETHYST_HOE.get()))
.add(ModItems.AMETHYST_HOE.getKey())
.add(findResourceKey(Items.GOLDEN_HOE))
.add(findResourceKey(Items.IRON_HOE))
.add(findResourceKey(Items.DIAMOND_HOE));
provider.addTag(ModItemTags.ROYAL_STEEL_SWORD_BASE)
.add(findResourceKey(ModItems.AMETHYST_SWORD.get()))
.add(ModItems.AMETHYST_SWORD.getKey())
.add(findResourceKey(Items.GOLDEN_SWORD))
.add(findResourceKey(Items.IRON_SWORD))
.add(findResourceKey(Items.DIAMOND_SWORD));
provider.addTag(ModItemTags.ROYAL_STEEL_SHOVEL_BASE)
.add(findResourceKey(ModItems.AMETHYST_SHOVEL.get()))
.add(ModItems.AMETHYST_SHOVEL.getKey())
.add(findResourceKey(Items.GOLDEN_SHOVEL))
.add(findResourceKey(Items.IRON_SHOVEL))
.add(findResourceKey(Items.DIAMOND_SHOVEL));

provider.addTag(ModItemTags.EMBER_METAL_PICKAXE_BASE)
.add(findResourceKey(ModItems.ROYAL_STEEL_PICKAXE.get()))
.add(ModItems.ROYAL_STEEL_PICKAXE.getKey())
.add(findResourceKey(Items.NETHERITE_PICKAXE));
provider.addTag(ModItemTags.EMBER_METAL_AXE_BASE)
.add(findResourceKey(ModItems.ROYAL_STEEL_AXE.get()))
.add(ModItems.ROYAL_STEEL_AXE.getKey())
.add(findResourceKey(Items.NETHERITE_AXE));
provider.addTag(ModItemTags.EMBER_METAL_HOE_BASE)
.add(findResourceKey(ModItems.ROYAL_STEEL_HOE.get()))
.add(ModItems.ROYAL_STEEL_HOE.getKey())
.add(findResourceKey(Items.NETHERITE_HOE));
provider.addTag(ModItemTags.EMBER_METAL_SWORD_BASE)
.add(findResourceKey(ModItems.ROYAL_STEEL_SWORD.get()))
.add(ModItems.ROYAL_STEEL_SWORD.getKey())
.add(findResourceKey(Items.NETHERITE_SWORD));
provider.addTag(ModItemTags.EMBER_METAL_SHOVEL_BASE)
.add(findResourceKey(ModItems.ROYAL_STEEL_SHOVEL.get()))
.add(ModItems.ROYAL_STEEL_SHOVEL.getKey())
.add(findResourceKey(Items.NETHERITE_SHOVEL));

provider.addTag(ModItemTags.GEMS)
.add(findResourceKey(Items.EMERALD))
.add(findResourceKey(ModItems.RUBY.get()))
.add(findResourceKey(ModItems.SAPPHIRE.get()))
.add(findResourceKey(ModItems.TOPAZ.get()));
.add(ModItems.RUBY.getKey())
.add(ModItems.SAPPHIRE.getKey())
.add(ModItems.TOPAZ.getKey());
provider.addTag(ModItemTags.GEM_BLOCKS)
.add(findResourceKey(Items.EMERALD_BLOCK))
.add(findResourceKey(ModBlocks.RUBY_BLOCK.asItem()))
Expand Down Expand Up @@ -103,9 +103,9 @@ public static void init(@NotNull RegistrateTagsProvider<Item> provider) {
.add(findResourceKey(Items.SWEET_BERRIES))
.add(findResourceKey(Items.GLOW_BERRIES));
provider.addTag(ModItemTags.WRENCH)
.add(findResourceKey(ModItems.ANVIL_HAMMER.get()))
.add(findResourceKey(ModItems.ROYAL_ANVIL_HAMMER.get()))
.add(findResourceKey(ModItems.EMBER_ANVIL_HAMMER.get()));
.add(ModItems.ANVIL_HAMMER.getKey())
.add(ModItems.ROYAL_ANVIL_HAMMER.getKey())
.add(ModItems.EMBER_ANVIL_HAMMER.getKey());
provider.addTag(ModItemTags.FIRE_STARTER)
.add(findResourceKey(Items.TORCH))
.add(findResourceKey(Items.SOUL_TORCH))
Expand All @@ -129,7 +129,7 @@ public static void init(@NotNull RegistrateTagsProvider<Item> provider) {
provider.addTag(ModItemTags.EXPLOSION_PROOF)
.add(findResourceKey(ModBlocks.EARTH_CORE_SHARD_BLOCK.asItem()))
.add(findResourceKey(ModBlocks.EARTH_CORE_SHARD_ORE.asItem()))
.add(findResourceKey(ModItems.EARTH_CORE_SHARD.get()));
.add(ModItems.EARTH_CORE_SHARD.getKey());
}

private static ResourceKey<Item> findResourceKey(Item item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public class BreakBlockEventListener {
@SubscribeEvent
public static void onBlockRemoved(BlockEvent.BreakEvent event) {
Player player = event.getPlayer();
if(!(player.level() instanceof ServerLevel serverLevel)) return;
ItemStack stack = player.getMainHandItem();
ModEnchantmentHelper.onPostBreakBlock(
(ServerLevel) player.level(),
serverLevel,
stack,
player,
EquipmentSlot.MAINHAND,
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/dev/dubhe/anvilcraft/init/ModBlockTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.jetbrains.annotations.NotNull;

public class ModBlockTags {

private static final String MEKANISM_MODID = "mekanism";
// mod tags
public static final TagKey<Block> UNDER_CAULDRON = bind("under_cauldron");
public static final TagKey<Block> MAGNET = bind("magnet");
Expand Down Expand Up @@ -59,10 +61,17 @@ public class ModBlockTags {
public static final TagKey<Block> INCORRECT_FOR_AMYTHEST_TOOL = bind("incorrect_for_amythest_tool");
public static final TagKey<Block> INCORRECT_FOR_EMBER_TOOL = bind("incorrect_for_ember_tool");

//mekanism tags
public static final TagKey<Block> MEKANISM_CARDBOARD_BOX_BLACKLIST = bindMekanism("cardboard_blacklist");

private static @NotNull TagKey<Block> bindC(String id) {
return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("c", id));
}

private static @NotNull TagKey<Block> bindMekanism(String id){
return TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(MEKANISM_MODID, id));
}

private static @NotNull TagKey<Block> bind(String id) {
return TagKey.create(Registries.BLOCK, AnvilCraft.of(id));
}
Expand Down
Loading