添加开箱音效

This commit is contained in:
Atsuihsio 2024-11-29 19:28:34 +08:00
parent bcd61542c1
commit f50f4c052a
10 changed files with 22 additions and 15 deletions

View file

@ -1,4 +1,4 @@
// 1.20.1 2024-11-29T11:09:46.7580865 Tags for minecraft:item mod id superbwarfare // 1.20.1 2024-11-29T19:04:10.4852137 Tags for minecraft:item mod id superbwarfare
cf8d49a8d2872286d1a9c3d4a7e1c2b7690db0b8 data/forge/tags/items/dusts.json cf8d49a8d2872286d1a9c3d4a7e1c2b7690db0b8 data/forge/tags/items/dusts.json
0fa06c2ff83bf09797e3ddff90f62d1124e645b4 data/forge/tags/items/dusts/coal_coke.json 0fa06c2ff83bf09797e3ddff90f62d1124e645b4 data/forge/tags/items/dusts/coal_coke.json
295ddf906b7133a0558d03e9a60eea18281fe430 data/forge/tags/items/dusts/iron.json 295ddf906b7133a0558d03e9a60eea18281fe430 data/forge/tags/items/dusts/iron.json
@ -48,7 +48,6 @@ aaa533157491a82b8e23b2914deef67c4078cbed data/superbwarfare/tags/items/rifle.jso
acd4d19dfadb71a1cec43e9c0f4a38fe8d3cf8cb data/superbwarfare/tags/items/shotgun.json acd4d19dfadb71a1cec43e9c0f4a38fe8d3cf8cb data/superbwarfare/tags/items/shotgun.json
4aca0fa3f8b9f2a4920041e35e46dae7e93d5482 data/superbwarfare/tags/items/smg.json 4aca0fa3f8b9f2a4920041e35e46dae7e93d5482 data/superbwarfare/tags/items/smg.json
13a23684e04832bea5dfbd2c0a9d9ed52dcb3422 data/superbwarfare/tags/items/sniper_rifle.json 13a23684e04832bea5dfbd2c0a9d9ed52dcb3422 data/superbwarfare/tags/items/sniper_rifle.json
ce4893378c0c18730fabad876dba059e91e9a0b1 data/superbwarfare/tags/items/tools.json
202756a5a9085f5883ca34424a79c1b7831101a9 data/superbwarfare/tags/items/use_handgun_ammo.json 202756a5a9085f5883ca34424a79c1b7831101a9 data/superbwarfare/tags/items/use_handgun_ammo.json
2899774c6325135847a85b09121ce25587aa275e data/superbwarfare/tags/items/use_rifle_ammo.json 2899774c6325135847a85b09121ce25587aa275e data/superbwarfare/tags/items/use_rifle_ammo.json
acd4d19dfadb71a1cec43e9c0f4a38fe8d3cf8cb data/superbwarfare/tags/items/use_shotgun_ammo.json acd4d19dfadb71a1cec43e9c0f4a38fe8d3cf8cb data/superbwarfare/tags/items/use_shotgun_ammo.json

View file

@ -1,6 +0,0 @@
{
"values": [
"superbwarfare:crowbar",
"create:wrench"
]
}

View file

@ -4,12 +4,14 @@ import com.atsuishio.superbwarfare.block.entity.ContainerBlockEntity;
import com.atsuishio.superbwarfare.entity.ICannonEntity; import com.atsuishio.superbwarfare.entity.ICannonEntity;
import com.atsuishio.superbwarfare.init.ModBlockEntities; import com.atsuishio.superbwarfare.init.ModBlockEntities;
import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -52,7 +54,7 @@ public class ContainerBlock extends BaseEntityBlock {
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) { public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
if (!pLevel.isClientSide) { if (!pLevel.isClientSide) {
ItemStack stack = pPlayer.getItemInHand(pHand); ItemStack stack = pPlayer.getItemInHand(pHand);
if (stack.is(ModTags.Items.TOOLS)) { if (stack.is(ModItems.CROWBAR.get())) {
BlockEntity blockEntity = pLevel.getBlockEntity(pPos); BlockEntity blockEntity = pLevel.getBlockEntity(pPos);
if (!(blockEntity instanceof ContainerBlockEntity containerBlockEntity)) return InteractionResult.PASS; if (!(blockEntity instanceof ContainerBlockEntity containerBlockEntity)) return InteractionResult.PASS;
@ -63,6 +65,11 @@ public class ContainerBlock extends BaseEntityBlock {
if (canOpen(pLevel, pPos, containerBlockEntity.entityType, containerBlockEntity.entity)) { if (canOpen(pLevel, pPos, containerBlockEntity.entityType, containerBlockEntity.entity)) {
pLevel.setBlockAndUpdate(pPos, pState.setValue(OPENED, true)); pLevel.setBlockAndUpdate(pPos, pState.setValue(OPENED, true));
if (!pLevel.isClientSide()) {
pLevel.playSound(null, BlockPos.containing(pPos.getX(), pPos.getY(), pPos.getZ()), ModSounds.OPEN.get(), SoundSource.BLOCKS, 1, 1);
} else {
pLevel.playLocalSound(pPos.getX(), pPos.getY(), pPos.getZ(), ModSounds.OPEN.get(), SoundSource.BLOCKS, 1, 1, false);
}
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} else { } else {
pPlayer.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.open"), true); pPlayer.displayClientMessage(Component.translatable("des.superbwarfare.container.fail.open"), true);

View file

@ -65,8 +65,6 @@ public class ModItemTagProvider extends ItemTagsProvider {
ModItems.GUNS.getEntries().forEach(registryObject -> this.tag(ModTags.Items.GUN).add(registryObject.get())); ModItems.GUNS.getEntries().forEach(registryObject -> this.tag(ModTags.Items.GUN).add(registryObject.get()));
this.tag(ModTags.Items.TOOLS).add(ModItems.CROWBAR.get());
this.tag(ModTags.Items.SMG).add(ModItems.VECTOR.get()); this.tag(ModTags.Items.SMG).add(ModItems.VECTOR.get());
this.tag(ModTags.Items.HANDGUN).add(ModItems.TRACHELIUM.get(), ModItems.GLOCK_17.get(), ModItems.GLOCK_18.get(), ModItems.M_1911.get()); this.tag(ModTags.Items.HANDGUN).add(ModItems.TRACHELIUM.get(), ModItems.GLOCK_17.get(), ModItems.GLOCK_18.get(), ModItems.M_1911.get());

View file

@ -155,7 +155,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
@Override @Override
public InteractionResult interact(Player player, InteractionHand hand) { public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) { if (player.isShiftKeyDown()) {
if (player.getMainHandItem().is(ModTags.Items.TOOLS) && this.getFirstPassenger() == null) { if (player.getMainHandItem().is(ModItems.CROWBAR.get()) && this.getFirstPassenger() == null) {
ItemStack stack = ContainerBlockItem.createInstance(this); ItemStack stack = ContainerBlockItem.createInstance(this);
if (!player.addItem(stack)){ if (!player.addItem(stack)){
player.drop(stack, false); player.drop(stack, false);

View file

@ -163,7 +163,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
@Override @Override
public InteractionResult interact(Player player, InteractionHand hand) { public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) { if (player.isShiftKeyDown()) {
if (player.getMainHandItem().is(ModTags.Items.TOOLS) && this.getFirstPassenger() == null) { if (player.getMainHandItem().is(ModItems.CROWBAR.get()) && this.getFirstPassenger() == null) {
ItemStack stack = ContainerBlockItem.createInstance(this); ItemStack stack = ContainerBlockItem.createInstance(this);
if (!player.addItem(stack)) { if (!player.addItem(stack)) {
player.drop(stack, false); player.drop(stack, false);

View file

@ -329,4 +329,6 @@ public class ModSounds {
public static final RegistryObject<SoundEvent> SHELL_CASING_NORMAL = REGISTRY.register("shell_casing_normal", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "shell_casing_normal"))); public static final RegistryObject<SoundEvent> SHELL_CASING_NORMAL = REGISTRY.register("shell_casing_normal", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "shell_casing_normal")));
public static final RegistryObject<SoundEvent> SHELL_CASING_SHOTGUN = REGISTRY.register("shell_casing_shotgun", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "shell_casing_shotgun"))); public static final RegistryObject<SoundEvent> SHELL_CASING_SHOTGUN = REGISTRY.register("shell_casing_shotgun", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "shell_casing_shotgun")));
public static final RegistryObject<SoundEvent> SHELL_CASING_50CAL = REGISTRY.register("shell_casing_50cal", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "shell_casing_50cal"))); public static final RegistryObject<SoundEvent> SHELL_CASING_50CAL = REGISTRY.register("shell_casing_50cal", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "shell_casing_50cal")));
public static final RegistryObject<SoundEvent> OPEN = REGISTRY.register("open", () -> SoundEvent.createVariableRangeEvent(new ResourceLocation(ModUtils.MODID, "open")));
} }

View file

@ -44,7 +44,6 @@ public class ModTags {
public static final TagKey<Item> MILITARY_ARMOR = tag("military_armor"); public static final TagKey<Item> MILITARY_ARMOR = tag("military_armor");
public static final TagKey<Item> MILITARY_ARMOR_HEAVY = tag("military_armor_heavy"); public static final TagKey<Item> MILITARY_ARMOR_HEAVY = tag("military_armor_heavy");
public static final TagKey<Item> TOOLS = tag("tools");
private static TagKey<Item> tag(String name) { private static TagKey<Item> tag(String name) {
return ItemTags.create(new ResourceLocation(ModUtils.MODID, name)); return ItemTags.create(new ResourceLocation(ModUtils.MODID, name));

View file

@ -2349,5 +2349,13 @@
"stream": false "stream": false
} }
] ]
},
"open": {
"sounds": [
{
"name": "superbwarfare:open",
"stream": false
}
]
} }
} }