From 24f5351c8338b96c00decd7a81b85bdbc14b534a Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Fri, 29 Nov 2024 10:43:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E7=AE=B1=E4=BD=BF=E7=94=A8=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=94=B9=E4=B8=BAtag=E4=B8=BAtools=E7=9A=84=E7=89=A9?= =?UTF-8?q?=E5=93=81=EF=BC=8C=E5=BC=80=E7=AE=B1=E4=BC=9A=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E5=86=85=E9=83=A8=E5=AE=9E=E4=BD=93=E7=A2=B0=E6=92=9E=E7=AE=B1?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E5=86=B3=E5=AE=9A=E6=98=AF=E5=90=A6=E8=83=BD?= =?UTF-8?q?=E5=A4=9F=E6=89=93=E5=BC=80=E7=AE=B1=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2e07f3c482445536d45c00e6abf223465c01c841 | 3 +- .../data/forge/tags/items/tools.json | 5 +++ .../superbwarfare/block/ContainerBlock.java | 36 +++++++++++++++---- .../datagen/ModItemTagProvider.java | 2 ++ 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/generated/resources/data/forge/tags/items/tools.json diff --git a/src/generated/resources/.cache/2e07f3c482445536d45c00e6abf223465c01c841 b/src/generated/resources/.cache/2e07f3c482445536d45c00e6abf223465c01c841 index 1f40516f4..1af76f000 100644 --- a/src/generated/resources/.cache/2e07f3c482445536d45c00e6abf223465c01c841 +++ b/src/generated/resources/.cache/2e07f3c482445536d45c00e6abf223465c01c841 @@ -1,4 +1,4 @@ -// 1.20.1 2024-11-27T01:38:22.7956251 Tags for minecraft:item mod id superbwarfare +// 1.20.1 2024-11-29T10:14:35.4350334 Tags for minecraft:item mod id superbwarfare cf8d49a8d2872286d1a9c3d4a7e1c2b7690db0b8 data/forge/tags/items/dusts.json 0fa06c2ff83bf09797e3ddff90f62d1124e645b4 data/forge/tags/items/dusts/coal_coke.json 295ddf906b7133a0558d03e9a60eea18281fe430 data/forge/tags/items/dusts/iron.json @@ -26,6 +26,7 @@ af6fd64b4a685c353f243763db268f7b2304c009 data/forge/tags/items/storage_blocks/le 30d1daa7590f7364b5bc2dc777a00caf2f5eecb0 data/forge/tags/items/storage_blocks/silver.json 3743c2790deca7e779d3e4b82f092de39b446988 data/forge/tags/items/storage_blocks/steel.json 144e54d908121dee498b2ebba3b24b09fd6f18d9 data/forge/tags/items/storage_blocks/tungsten.json +ce4893378c0c18730fabad876dba059e91e9a0b1 data/forge/tags/items/tools.json 4d4dfd25a2a749e000e1bb742c2f984d4e094e5d data/superbwarfare/tags/items/cannot_reload.json cedce5ff7bbc95b40cbfced0f03a3da712118049 data/superbwarfare/tags/items/can_apply_barrel.json 4b0864ba4b2bb2ca3b30bdc2fefe3077f5020466 data/superbwarfare/tags/items/can_apply_grip.json diff --git a/src/generated/resources/data/forge/tags/items/tools.json b/src/generated/resources/data/forge/tags/items/tools.json new file mode 100644 index 000000000..d90c92cd6 --- /dev/null +++ b/src/generated/resources/data/forge/tags/items/tools.json @@ -0,0 +1,5 @@ +{ + "values": [ + "superbwarfare:crowbar" + ] +} \ No newline at end of file diff --git a/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java b/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java index 314db7474..307bd18f6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/ContainerBlock.java @@ -1,8 +1,9 @@ package com.atsuishio.superbwarfare.block; import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity; +import com.atsuishio.superbwarfare.entity.ICannonEntity; import com.atsuishio.superbwarfare.init.ModBlockEntities; -import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModEntities; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -10,6 +11,8 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; @@ -29,6 +32,7 @@ import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraftforge.common.Tags; import javax.annotation.Nullable; import java.util.List; @@ -48,13 +52,16 @@ public class ContainerBlock extends BaseEntityBlock { public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) { if (!pLevel.isClientSide) { ItemStack stack = pPlayer.getItemInHand(pHand); - if (stack.is(ModItems.CROWBAR.get())) { + if (stack.is(Tags.Items.TOOLS)) { + BlockEntity blockEntity = pLevel.getBlockEntity(pPos); + if (!(blockEntity instanceof ContainerBlockEntity containerBlockEntity)) return InteractionResult.PASS; + if (!hasEntity(pLevel, pPos)) { pPlayer.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.empty"), true); return InteractionResult.PASS; } - if (canOpen(pLevel, pPos)) { + if (canOpen(pLevel, pPos, containerBlockEntity.entityType, containerBlockEntity.entity)) { pLevel.setBlockAndUpdate(pPos, pState.setValue(OPENED, true)); return InteractionResult.SUCCESS; } else { @@ -73,12 +80,27 @@ public class ContainerBlock extends BaseEntityBlock { return containerBlockEntity.entity != null || containerBlockEntity.entityType != null; } - public boolean canOpen(Level pLevel, BlockPos pPos) { + public boolean canOpen(Level pLevel, BlockPos pPos, EntityType entityType, Entity entity) { boolean flag = true; - for (int i = -4; i < 5; i++) { - for (int j = 0; j < 7; j++) { - for (int k = -4; k < 5; k++) { + int w = 0; + int h = 0; + + boolean extra = entityType == ModEntities.MLE_1934.get() || entityType == ModEntities.MK_42.get() || entity instanceof ICannonEntity; + + if (entityType != null) { + w = (int) (entityType.getDimensions().width / 2 + (extra ? 2 : 0)); + h = (int) (entityType.getDimensions().height + (extra ? 2 : 0)); + } + + if (entity != null) { + w = (int) (entity.getType().getDimensions().width / 2 + (extra ? 2 : 0)); + h = (int) (entity.getType().getDimensions().height + (extra ? 2 : 0)); + } + + for (int i = -w; i < w + 1; i++) { + for (int j = 0; j < h; j++) { + for (int k = -w; k < w + 1; k++) { if (i == 0 && j == 0 && k == 0) { continue; } diff --git a/src/main/java/com/atsuishio/superbwarfare/datagen/ModItemTagProvider.java b/src/main/java/com/atsuishio/superbwarfare/datagen/ModItemTagProvider.java index 74348bbd3..012929630 100644 --- a/src/main/java/com/atsuishio/superbwarfare/datagen/ModItemTagProvider.java +++ b/src/main/java/com/atsuishio/superbwarfare/datagen/ModItemTagProvider.java @@ -60,6 +60,8 @@ public class ModItemTagProvider extends ItemTagsProvider { this.tag(Tags.Items.ORES_IN_GROUND_STONE).add(ModItems.GALENA_ORE.get(), ModItems.SCHEELITE_ORE.get(), ModItems.SILVER_ORE.get()); this.tag(Tags.Items.ORES_IN_GROUND_DEEPSLATE).add(ModItems.DEEPSLATE_GALENA_ORE.get(), ModItems.DEEPSLATE_SCHEELITE_ORE.get(), ModItems.DEEPSLATE_SILVER_ORE.get()); + this.tag(Tags.Items.TOOLS).add(ModItems.CROWBAR.get()); + this.tag(forgeTag("plates")).addTags(forgeTag("plates/copper")); this.tag(forgeTag("plates/copper")).add(ModItems.COPPER_PLATE.get());