Skip to content

Commit

Permalink
Block Code Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Builderdog841 committed Jun 17, 2024
1 parent 66a5967 commit aced8fd
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package net.builderdog.ancient_aether.block;

import com.aetherteam.aether.block.natural.AetherDoubleDropsLeaves;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;

public class AncientAetherBlockBuilders {

public static Block leaves(MapColor mapColor, SoundType sound) {
return new AetherDoubleDropsLeaves(
BlockBehaviour.Properties.of()
.mapColor(mapColor)
.strength(0.2F)
.randomTicks()
.sound(sound)
.noOcclusion()
.isValidSpawn(AncientAetherBlocks::ocelotOrParrot)
.isSuffocating(AncientAetherBlocks::never)
.isViewBlocking(AncientAetherBlocks::never)
.ignitedByLava()
.pushReaction(PushReaction.DESTROY)
.isRedstoneConductor(AncientAetherBlocks::never)
);
}

public static WallBlock logWall() {
return new WallBlock(
BlockBehaviour.Properties.of()
.mapColor(MapColor.WOOD)
.instrument(NoteBlockInstrument.BASS)
.ignitedByLava().strength(2.0F)
.sound(SoundType.WOOD)
);
}

public static Block dungeonBlock(MapColor mapColor) {
return new Block(
BlockBehaviour.Properties.of()
.mapColor(mapColor)
.instrument(NoteBlockInstrument.BASEDRUM)
.strength(0.5F, 6.0F)
.requiresCorrectToolForDrops()
);
}

public static RotatedPillarBlock dungeonMosaic(MapColor mapColor) {
return new RotatedPillarBlock(
BlockBehaviour.Properties.of()
.mapColor(mapColor)
.instrument(NoteBlockInstrument.BASEDRUM)
.strength(0.5F, 6.0F)
.requiresCorrectToolForDrops()
);
}

public static boolean never(BlockState test1, BlockGetter test2, BlockPos test3) {
return false;
}
public static boolean always(BlockState test1, BlockGetter test2, BlockPos test3) {
return true;
}

public static boolean ocelotOrParrot(BlockState state, BlockGetter getter, BlockPos pos, EntityType<?> entity) {
return entity == EntityType.OCELOT || entity == EntityType.PARROT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.aetherteam.aether.block.dungeon.TrappedBlock;
import com.aetherteam.aether.block.dungeon.TreasureDoorwayBlock;
import com.aetherteam.aether.block.natural.AetherDoubleDropBlock;
import com.aetherteam.aether.block.natural.AetherDoubleDropsLeaves;
import com.aetherteam.aether.block.natural.AetherDoubleDropsOreBlock;
import com.aetherteam.aether.block.natural.AetherLogBlock;
import com.aetherteam.aether.effect.AetherEffects;
Expand All @@ -17,18 +16,13 @@
import net.builderdog.ancient_aether.entity.AncientAetherEntityTypes;
import net.builderdog.ancient_aether.item.AncientAetherItems;
import net.builderdog.ancient_aether.world.tree.AncientAetherTreeGrowers;
import net.minecraft.core.BlockPos;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import net.neoforged.neoforge.registries.DeferredBlock;
Expand All @@ -39,7 +33,7 @@
import static net.minecraft.world.level.block.Blocks.*;

@SuppressWarnings("deprecation")
public class AncientAetherBlocks {
public class AncientAetherBlocks extends AncientAetherBlockBuilders {
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(AncientAether.MODID);

public static final DeferredBlock<Block> GRAVITY_GRAVEL = register("gravity_gravel", () -> new AetherDoubleDropBlock(Block.Properties.of().mapColor(MapColor.TERRACOTTA_PURPLE).jumpFactor(1.5F).strength(0.25F).sound(SoundType.GRAVEL)));
Expand Down Expand Up @@ -226,53 +220,6 @@ public class AncientAetherBlocks {
public static final DeferredBlock<FlowerPotBlock> POTTED_WYND_THISTLE = BLOCKS.register("potted_wynd_thistle", () -> new FlowerPotBlock(() -> (FlowerPotBlock) Blocks.FLOWER_POT, WYND_THISTLE, Block.Properties.ofFullCopy(Blocks.FLOWER_POT)));
public static final DeferredBlock<FlowerPotBlock> POTTED_ELEVETIA = BLOCKS.register("potted_elevetia", () -> new FlowerPotBlock(() -> (FlowerPotBlock) Blocks.FLOWER_POT, ELEVETIA, Block.Properties.ofFullCopy(Blocks.FLOWER_POT)));

private static Block leaves(MapColor mapColor, SoundType sound) {
return new AetherDoubleDropsLeaves(
BlockBehaviour.Properties.of()
.mapColor(mapColor)
.strength(0.2F)
.randomTicks()
.sound(sound)
.noOcclusion()
.isValidSpawn(AncientAetherBlocks::ocelotOrParrot)
.isSuffocating(AncientAetherBlocks::never)
.isViewBlocking(AncientAetherBlocks::never)
.ignitedByLava()
.pushReaction(PushReaction.DESTROY)
.isRedstoneConductor(AncientAetherBlocks::never)
);
}

private static WallBlock logWall() {
return new WallBlock(
BlockBehaviour.Properties.of()
.mapColor(MapColor.WOOD)
.instrument(NoteBlockInstrument.BASS)
.ignitedByLava().strength(2.0F)
.sound(SoundType.WOOD)
);
}

private static Block dungeonBlock(MapColor mapColor) {
return new Block(
BlockBehaviour.Properties.of()
.mapColor(mapColor)
.instrument(NoteBlockInstrument.BASEDRUM)
.strength(0.5F, 6.0F)
.requiresCorrectToolForDrops()
);
}

private static RotatedPillarBlock dungeonMosaic(MapColor mapColor) {
return new RotatedPillarBlock(
BlockBehaviour.Properties.of()
.mapColor(mapColor)
.instrument(NoteBlockInstrument.BASEDRUM)
.strength(0.5F, 6.0F)
.requiresCorrectToolForDrops()
);
}

public static void registerPots() {
FlowerPotBlock pot = (FlowerPotBlock) Blocks.FLOWER_POT;
pot.addPlant(AncientAetherBlocks.CRYSTAL_SKYROOT_SAPLING.getId(), AncientAetherBlocks.POTTED_CRYSTAL_SKYROOT_SAPLING);
Expand Down Expand Up @@ -335,17 +282,6 @@ public static void registerFlammability() {
fireBlockAccessor.callSetFlammable(AncientAetherBlocks.SAKURA_FENCE.get(), 5, 20);
}

private static boolean never(BlockState test1, BlockGetter test2, BlockPos test3) {
return false;
}
private static boolean always(BlockState test1, BlockGetter test2, BlockPos test3) {
return true;
}

private static boolean ocelotOrParrot(BlockState state, BlockGetter getter, BlockPos pos, EntityType<?> entity) {
return entity == EntityType.OCELOT || entity == EntityType.PARROT;
}

private static <T extends Block> DeferredBlock<T> register(String name, Supplier<T> block) {
DeferredBlock<T> toReturn = BLOCKS.register(name, block);
registerBlockItem(name, toReturn);
Expand Down

0 comments on commit aced8fd

Please sign in to comment.