Search in sources :

Example 1 with TotemWoodType

use of pokefenn.totemic.api.TotemWoodType in project Totemic by TeamTotemic.

the class TotemKnifeItem method useOn.

@SuppressWarnings("resource")
@Override
public InteractionResult useOn(UseOnContext c) {
    if (c.getPlayer().isCrouching()) {
        // TODO
        return InteractionResult.FAIL;
    } else {
        BlockState state = c.getLevel().getBlockState(c.getClickedPos());
        TotemWoodType woodType = TotemWoodType.fromLog(state);
        if (woodType == null) {
            // Fall back to oak if it is an unrecognized log type
            if (BlockTags.LOGS_THAT_BURN.contains(state.getBlock()))
                woodType = TotemWoodType.OAK;
            else
                return InteractionResult.FAIL;
        }
        BlockState newState;
        TotemEffect effect = getCarvingEffect(c.getItemInHand());
        if (effect != null) {
            newState = ModBlocks.getTotemPoles().get(woodType, effect).getStateForPlacement(new BlockPlaceContext(c));
        } else {
            newState = ModBlocks.getTotemBases().get(woodType).getStateForPlacement(new BlockPlaceContext(c));
        }
        c.getLevel().setBlock(c.getClickedPos(), newState, 3);
        newState.getBlock().setPlacedBy(c.getLevel(), c.getClickedPos(), newState, c.getPlayer(), c.getItemInHand());
        c.getItemInHand().hurtAndBreak(1, c.getPlayer(), player -> player.broadcastBreakEvent(c.getHand()));
        c.getLevel().playSound(c.getPlayer(), c.getClickedPos(), SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
        return InteractionResult.sidedSuccess(c.getLevel().isClientSide);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) TotemWoodType(pokefenn.totemic.api.TotemWoodType) TotemEffect(pokefenn.totemic.api.totem.TotemEffect)

Example 2 with TotemWoodType

use of pokefenn.totemic.api.TotemWoodType 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

TotemWoodType (pokefenn.totemic.api.TotemWoodType)2 TotemEffect (pokefenn.totemic.api.totem.TotemEffect)2 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)1 Properties (net.minecraft.world.level.block.state.BlockBehaviour.Properties)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 TotemBaseBlock (pokefenn.totemic.block.totem.TotemBaseBlock)1 TotemPoleBlock (pokefenn.totemic.block.totem.TotemPoleBlock)1