diff --git a/README.md b/README.md index 582a73c..b7eea63 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,123 @@ *This api works for minecraft versions 1.19.4* An API for easily creating custom blocks that is heavily inspired by the Fabric API. -For information on how to use this api, see the GitHub wiki. +For information on how to use this API, see the GitHub wiki. + +## Commands + +| Command | Description | Permission | +|-------------------------|---------------------------------------------------------------------------------|-----------------------------| +| /listCustomBlocks | Displays a Gui listing all Custom Blocks. Use left click to get a custom block. | `customblocks.commands.gui` | +| /getCustomBlock | Get the custom block provided. | `customblocks.commands.get` | + +## Screenshots + +
Grape Block + +
Code + +~~~java +public class GrapesBlock extends CustomBlock { + + public static BooleanProperty BERRIES; + + static { + BERRIES = Properties.BERRIES; + } + + public GrapesBlock(BlockSettings settings) { + super(settings, 4, new ItemBuilder(Material.EMERALD).setCustomModelData(4).setDisplayName("§r§6" + settings.getName()).build()); + setDefaultState(getDefaultState().with(BERRIES, false)); + } + + @Override + public void appendProperties(PropertyListBuilder propertyListBuilder) { + propertyListBuilder.add(BERRIES); + } + + @Override + public CustomBlockState getPlacementState(ItemPlacementContext ctx) { + return getDefaultState().with(BERRIES, true); + } + + @Override + public ActionResult onUse(CustomBlockState state, World world, Location location, Player player, EquipmentSlot hand) { + if (state.get(BERRIES) == false) { + return ActionResult.SUCCESS; + } + state.with(BERRIES, false); + state.update(); + + //DropItem + ItemStack stack = new ItemStack(Material.SWEET_BERRIES); + stack.setAmount(blockRandom.nextInt(2) + 1); + world.dropItem(location.add(settings.getWidth() / 2, 0, settings.getWidth() / 2), stack); + + //Regrow + new BukkitRunnable() { + + @Override + public void run() { + state.with(BERRIES, true); + state.update(); + } + }.runTaskLater(CustomBlocksApiPlugin.getInstance(), blockRandom.nextInt(60) + 200); + + return ActionResult.SUCCESS; + } + + @Override + public void applyInitialModelTransformations(ItemDisplay display) { + display.setRotation(blockRandom.nextInt(360), 0); + } + + @Override + public CMDLookupTable createCMDLookupTable(CMDLookupTableBuilder tableBuilder) { + return tableBuilder.with(BERRIES, false).hasCustomModelData(5).addElement() + .with(BERRIES, true).hasCustomModelData(4).addElement().build(); + } +} +~~~ + +
+ +
Animated Computer Block + +
Code + +~~~java +public class AnimatedComputerBlock extends SimpleAnimatedBlock { + + private static BooleanProperty ENABLED; + + static { + ENABLED = Properties.ENABLED; + } + + public AnimatedComputerBlock(BlockSettings settings) { + super(settings, new ItemBuilder(Material.DIAMOND).setCustomModelData(6).setDisplayName("§r§6" + settings.getName()).build(), 10, 7, 6); + setDefaultState(getDefaultState().with(ENABLED, false)); + } + + @Override + public void appendProperties(PropertyListBuilder propertyListBuilder) { + propertyListBuilder.add(ENABLED); + } + + @Override + public void onNeighborUpdate(CustomBlockState state, World world, Location location, CustomBlock block, Location fromPos) { + state.with(ENABLED, location.getBlock().getBlockPower() > 0); + state.update(); + } + + @Override + protected boolean shouldPlayFrames(TickState state) { + return state.getCustomBlockState().get(ENABLED); + } +} +~~~ + +
## Maven Dependency diff --git a/images/computer.png b/images/computer.png new file mode 100644 index 0000000..9f6e078 Binary files /dev/null and b/images/computer.png differ diff --git a/images/grapes.png b/images/grapes.png new file mode 100644 index 0000000..f94f251 Binary files /dev/null and b/images/grapes.png differ