Search in sources :

Example 1 with TotemPoleBlock

use of pokefenn.totemic.block.totem.TotemPoleBlock in project Totemic by TeamTotemic.

the class TileTotemBase method calculateTotemEffects.

private void calculateTotemEffects() {
    totemEffectList.clear();
    totemEffects.clear();
    for (int i = 0; i < TotemEffectAPI.MAX_POLE_SIZE; i++) {
        Block block = level.getBlockState(worldPosition.above(i + 1)).getBlock();
        if (block instanceof TotemPoleBlock) {
            TotemEffect effect = ((TotemPoleBlock) block).effect;
            totemEffectList.add(effect);
            totemEffects.add(effect);
        } else
            break;
    }
    // Calculate the greatest common divisor of all the intervals of the effects
    commonTotemEffectInterval = totemEffects.elementSet().stream().mapToInt(TotemEffect::getInterval).filter(// Integer.MAX_VALUE is a prime number, so we don't want it in the GCD calculation
    i -> i != Integer.MAX_VALUE).reduce(IntMath::gcd).orElse(Integer.MAX_VALUE);
}
Also used : Multiset(com.google.common.collect.Multiset) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock) ModTileEntities(pokefenn.totemic.init.ModTileEntities) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) TotemicCapabilities(pokefenn.totemic.api.TotemicCapabilities) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) Capability(net.minecraftforge.common.capabilities.Capability) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) List(java.util.List) IntMath(com.google.common.math.IntMath) MusicAcceptor(pokefenn.totemic.api.music.MusicAcceptor) HashMultiset(com.google.common.collect.HashMultiset) BlockPos(net.minecraft.core.BlockPos) TotemEffectAPI(pokefenn.totemic.api.totem.TotemEffectAPI) Block(net.minecraft.world.level.block.Block) Level(net.minecraft.world.level.Level) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IntMath(com.google.common.math.IntMath) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock) Block(net.minecraft.world.level.block.Block) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock)

Example 2 with TotemPoleBlock

use of pokefenn.totemic.block.totem.TotemPoleBlock in project Totemic by TeamTotemic.

the class ModBlocks method init.

@SubscribeEvent
public static void init(RegistryEvent.Register<Block> event) {
    internallyRegisterTotemEffects();
    for (TotemWoodType woodType : TotemWoodType.getWoodTypes()) {
        Properties blockProperties = Properties.of(Material.WOOD, woodType.getWoodColor()).strength(2, 5).sound(SoundType.WOOD);
        TotemBaseBlock totemBase = new TotemBaseBlock(woodType, blockProperties);
        totemBase.setRegistryName(Totemic.MOD_ID, woodType.getName() + "_totem_base");
        event.getRegistry().register(totemBase);
        totemBases.put(woodType, totemBase);
        blocksWithItemBlock.add(totemBase);
        for (TotemEffect totemEffect : totemEffectsToRegister) {
            TotemPoleBlock totemPole = new TotemPoleBlock(woodType, totemEffect, blockProperties);
            totemPole.setRegistryName(Totemic.MOD_ID, woodType.getName() + "_totem_pole_" + totemEffect.getRegistryName().getPath());
            event.getRegistry().register(totemPole);
            totemPoles.put(woodType, totemEffect, totemPole);
            blocksWithItemBlock.add(totemPole);
        }
    }
}
Also used : TotemWoodType(pokefenn.totemic.api.TotemWoodType) Properties(net.minecraft.world.level.block.state.BlockBehaviour.Properties) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) TotemBaseBlock(pokefenn.totemic.block.totem.TotemBaseBlock) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

TotemEffect (pokefenn.totemic.api.totem.TotemEffect)2 TotemPoleBlock (pokefenn.totemic.block.totem.TotemPoleBlock)2 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 IntMath (com.google.common.math.IntMath)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 Level (net.minecraft.world.level.Level)1 Block (net.minecraft.world.level.block.Block)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 Properties (net.minecraft.world.level.block.state.BlockBehaviour.Properties)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 Capability (net.minecraftforge.common.capabilities.Capability)1 LazyOptional (net.minecraftforge.common.util.LazyOptional)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 TotemWoodType (pokefenn.totemic.api.TotemWoodType)1