Merge pull request 'feat/5-sounds' (#7) from feat/5-sounds into 1.20.1
Reviewed-on: #7
This commit is contained in:
@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"block.firefly_bush.idle": {
|
||||||
|
"sounds": [
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush1",
|
||||||
|
"volume": 4.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush2",
|
||||||
|
"volume": 4.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush3",
|
||||||
|
"volume": 4.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush4",
|
||||||
|
"volume": 4.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush5",
|
||||||
|
"volume": 4.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush6",
|
||||||
|
"volume": 4.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush7",
|
||||||
|
"volume": 4.0,
|
||||||
|
"weight": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush8",
|
||||||
|
"volume": 4.0,
|
||||||
|
"weight": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush9",
|
||||||
|
"volume": 4.0,
|
||||||
|
"weight": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush10",
|
||||||
|
"volume": 4.0,
|
||||||
|
"weight": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "firefly_bush_backport:block/firefly_bush/firefly_bush11",
|
||||||
|
"volume": 4.0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"subtitle": "sound.firefly_bush_backport.block.firefly_bush.idle"
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,19 @@
|
|||||||
package dev.micle.firefly_bush_backport.block;
|
package dev.micle.firefly_bush_backport.block;
|
||||||
|
|
||||||
|
import dev.micle.firefly_bush_backport.sound.ModSounds;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
import net.minecraft.world.level.block.BonemealableBlock;
|
import net.minecraft.world.level.block.BonemealableBlock;
|
||||||
import net.minecraft.world.level.block.BushBlock;
|
import net.minecraft.world.level.block.BushBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.levelgen.Heightmap;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -20,28 +24,45 @@ public class FireflyBushBlock extends BushBlock implements BonemealableBlock {
|
|||||||
private static final int FIREFLY_SPAWN_MAX_BRIGHTNESS_LEVEL = 13;
|
private static final int FIREFLY_SPAWN_MAX_BRIGHTNESS_LEVEL = 13;
|
||||||
private static final int FIREFLY_AMBIENT_SOUND_CHANCE_ONE_IN = 30;
|
private static final int FIREFLY_AMBIENT_SOUND_CHANCE_ONE_IN = 30;
|
||||||
|
|
||||||
public FireflyBushBlock(Properties pProperties) {
|
public FireflyBushBlock(Properties properties) {
|
||||||
super(pProperties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void animateTick(BlockState pState, Level pLevel, BlockPos pPos, RandomSource pRandom) {
|
@ParametersAreNonnullByDefault
|
||||||
super.animateTick(pState, pLevel, pPos, pRandom);
|
public void animateTick(BlockState blockState, Level level, BlockPos blockPos, RandomSource randomSource) {
|
||||||
|
if (randomSource.nextInt(FIREFLY_AMBIENT_SOUND_CHANCE_ONE_IN) == 0
|
||||||
|
&& isMoonVisible(level)
|
||||||
|
&& level.getHeight(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, blockPos.getX(), blockPos.getZ()) <= blockPos.getY()) {
|
||||||
|
level.playLocalSound(blockPos, ModSounds.FIREFLY_BUSH_IDLE.get(), SoundSource.AMBIENT, 1.0F, 1.0F, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMoonVisible(Level level) {
|
||||||
|
if (!level.dimensionType().natural()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
int i = (int) (level.getDayTime() % 24000L);
|
||||||
|
return i >= 12600 && i <= 23400;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValidBonemealTarget(LevelReader pLevel, BlockPos pPos, BlockState pState, boolean pIsClient) {
|
@ParametersAreNonnullByDefault
|
||||||
return hasSpreadableNeighbourPos(pLevel, pPos, pState);
|
public boolean isValidBonemealTarget(LevelReader level, BlockPos blockPos, BlockState blockState, boolean isClient) {
|
||||||
|
return hasSpreadableNeighbourPos(level, blockPos, blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBonemealSuccess(Level pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) {
|
@ParametersAreNonnullByDefault
|
||||||
|
public boolean isBonemealSuccess(Level level, RandomSource randomSource, BlockPos blockPos, BlockState blockState) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performBonemeal(ServerLevel pLevel, RandomSource pRandom, BlockPos pPos, BlockState pState) {
|
@ParametersAreNonnullByDefault
|
||||||
findSpreadableNeighbourPos(pLevel, pPos, pState).ifPresent(x -> pLevel.setBlockAndUpdate(x, this.defaultBlockState()));
|
public void performBonemeal(ServerLevel level, RandomSource randomSource, BlockPos blockPos, BlockState blockState) {
|
||||||
|
findSpreadableNeighbourPos(level, blockPos, blockState).ifPresent(x -> level.setBlockAndUpdate(x, this.defaultBlockState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean hasSpreadableNeighbourPos(LevelReader levelReader, BlockPos blockPos, BlockState blockState) {
|
static boolean hasSpreadableNeighbourPos(LevelReader levelReader, BlockPos blockPos, BlockState blockState) {
|
||||||
|
@ -3,6 +3,7 @@ package dev.micle.firefly_bush_backport.data;
|
|||||||
import dev.micle.firefly_bush_backport.FireflyBushBackport;
|
import dev.micle.firefly_bush_backport.FireflyBushBackport;
|
||||||
import dev.micle.firefly_bush_backport.data.client.ModBlockStateProvider;
|
import dev.micle.firefly_bush_backport.data.client.ModBlockStateProvider;
|
||||||
import dev.micle.firefly_bush_backport.data.client.ModItemModelProvider;
|
import dev.micle.firefly_bush_backport.data.client.ModItemModelProvider;
|
||||||
|
import dev.micle.firefly_bush_backport.data.client.ModSoundDefinitionsProvider;
|
||||||
import net.minecraft.data.DataGenerator;
|
import net.minecraft.data.DataGenerator;
|
||||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||||
import net.minecraftforge.data.event.GatherDataEvent;
|
import net.minecraftforge.data.event.GatherDataEvent;
|
||||||
@ -16,7 +17,8 @@ public class DataGenerators {
|
|||||||
DataGenerator generator = event.getGenerator();
|
DataGenerator generator = event.getGenerator();
|
||||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||||
|
|
||||||
generator.addProvider(event.includeServer(), new ModBlockStateProvider(generator, existingFileHelper));
|
generator.addProvider(event.includeClient(), new ModBlockStateProvider(generator, existingFileHelper));
|
||||||
generator.addProvider(event.includeServer(), new ModItemModelProvider(generator, existingFileHelper));
|
generator.addProvider(event.includeClient(), new ModItemModelProvider(generator, existingFileHelper));
|
||||||
|
generator.addProvider(event.includeClient(), new ModSoundDefinitionsProvider(generator, existingFileHelper));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package dev.micle.firefly_bush_backport.data.client;
|
||||||
|
|
||||||
|
import dev.micle.firefly_bush_backport.FireflyBushBackport;
|
||||||
|
import dev.micle.firefly_bush_backport.sound.ModSounds;
|
||||||
|
import net.minecraft.data.DataGenerator;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||||
|
import net.minecraftforge.common.data.SoundDefinitionsProvider;
|
||||||
|
|
||||||
|
public class ModSoundDefinitionsProvider extends SoundDefinitionsProvider {
|
||||||
|
public ModSoundDefinitionsProvider(DataGenerator generator, ExistingFileHelper existingFileHelper) {
|
||||||
|
super(generator.getPackOutput(), FireflyBushBackport.MOD_ID, existingFileHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerSounds() {
|
||||||
|
add(ModSounds.FIREFLY_BUSH_IDLE, definition()
|
||||||
|
.subtitle("sound." + FireflyBushBackport.MOD_ID + ".block.firefly_bush.idle")
|
||||||
|
.with(
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush1"))
|
||||||
|
.volume(4),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush2"))
|
||||||
|
.volume(4),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush3"))
|
||||||
|
.volume(4),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush4"))
|
||||||
|
.volume(4),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush5"))
|
||||||
|
.volume(4),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush6"))
|
||||||
|
.volume(4),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush7"))
|
||||||
|
.volume(4)
|
||||||
|
.weight(2),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush8"))
|
||||||
|
.volume(4)
|
||||||
|
.weight(2),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush9"))
|
||||||
|
.volume(4)
|
||||||
|
.weight(2),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush10"))
|
||||||
|
.volume(4)
|
||||||
|
.weight(2),
|
||||||
|
sound(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, "block/firefly_bush/firefly_bush11"))
|
||||||
|
.volume(4)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import dev.micle.firefly_bush_backport.block.ModBlocks;
|
|||||||
import dev.micle.firefly_bush_backport.config.Config;
|
import dev.micle.firefly_bush_backport.config.Config;
|
||||||
import dev.micle.firefly_bush_backport.creative_mode_tab.ModCreativeModeTabs;
|
import dev.micle.firefly_bush_backport.creative_mode_tab.ModCreativeModeTabs;
|
||||||
import dev.micle.firefly_bush_backport.item.ModItems;
|
import dev.micle.firefly_bush_backport.item.ModItems;
|
||||||
|
import dev.micle.firefly_bush_backport.sound.ModSounds;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
@ -29,6 +30,7 @@ public class Proxy implements IProxy {
|
|||||||
ModBlocks.register(modEventBus);
|
ModBlocks.register(modEventBus);
|
||||||
ModItems.register(modEventBus);
|
ModItems.register(modEventBus);
|
||||||
ModCreativeModeTabs.register(modEventBus);
|
ModCreativeModeTabs.register(modEventBus);
|
||||||
|
ModSounds.register(modEventBus);
|
||||||
|
|
||||||
// Register mod event bus listeners
|
// Register mod event bus listeners
|
||||||
modEventBus.addListener(Proxy::setup);
|
modEventBus.addListener(Proxy::setup);
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package dev.micle.firefly_bush_backport.sound;
|
||||||
|
|
||||||
|
import dev.micle.firefly_bush_backport.FireflyBushBackport;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.sounds.SoundEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
|
||||||
|
public class ModSounds {
|
||||||
|
public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, FireflyBushBackport.MOD_ID);
|
||||||
|
|
||||||
|
public static final RegistryObject<SoundEvent> FIREFLY_BUSH_IDLE = registerSoundEvent("block.firefly_bush.idle");
|
||||||
|
|
||||||
|
public static void register(IEventBus modEventBus) {
|
||||||
|
SOUND_EVENTS.register(modEventBus);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RegistryObject<SoundEvent> registerSoundEvent(String name) {
|
||||||
|
return SOUND_EVENTS.register(name, () -> SoundEvent.createVariableRangeEvent(ResourceLocation.fromNamespaceAndPath(FireflyBushBackport.MOD_ID, name)));
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"itemGroup.firefly_bush_backport.main": "Firefly Bush Backport",
|
"itemGroup.firefly_bush_backport.main": "Firefly Bush Backport",
|
||||||
"block.firefly_bush_backport.firefly_bush": "Firefly Bush"
|
"block.firefly_bush_backport.firefly_bush": "Firefly Bush",
|
||||||
|
"sound.firefly_bush_backport.block.firefly_bush.idle": "Fireflies buzz"
|
||||||
}
|
}
|
Reference in New Issue
Block a user