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);
}
}
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);
}
}
}
Aggregations