Skip to content

Commit

Permalink
Javadocs and more
Browse files Browse the repository at this point in the history
  • Loading branch information
kindlich committed May 30, 2020
1 parent 6550369 commit 98fbdc1
Show file tree
Hide file tree
Showing 22 changed files with 655 additions and 436 deletions.
21 changes: 9 additions & 12 deletions src/main/java/com/blamejared/contenttweaker/BracketHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@

import java.util.*;

/**
* I advise against using the static methods in this class directly as they may be merged into CrT's BEP at any point.
* If you need to access the Bracket Expression Parser methods dynamically, you can use
* ```zencode
* var myName = "misc";
* <itemgroup:${myName}>
* ```
*/
@ZenRegister
@ZenCodeType.Name("mods.contenttweaker.BracketHandlers")
@Document("mods/contenttweaker/BracketHandlers")
@Document("mods/contenttweaker/API/BracketHandlers")
public class BracketHandlers {

/**
Expand Down Expand Up @@ -63,15 +71,4 @@ public static MCToolType getToolType(String tokens) {
// }
//

@ZenCodeType.Method
@BracketResolver("blockstateproperty")
public static MCBlockStateProperty getBlockStateProperty(String tokens) {
final MCBlockStateProperty fromString = MCBlockStateProperty.getFromString(tokens.toUpperCase());
if(fromString != null) {
return fromString;
}
throw new IllegalArgumentException("Could not find block state Property <blockstateproperty:" + tokens + ">!");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public static void generateStuffForMyModId(String myModId) {
public static void registerBlock(IIsCoTBlock block) {
registry.addBlock(block);
registry.addItem(block.getItem());
CraftTweakerAPI.logInfo("Registered Block %s", block.getMCResourceLocation().getInternal());
}

public static void registerItem(IIsCotItem item) {
registry.addItem(item);
CraftTweakerAPI.logInfo("Registered Item %s", item.getMCResourceLocation().getInternal());
}

public static void complete() {
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/com/blamejared/contenttweaker/api/IIsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,34 @@
import com.blamejared.contenttweaker.*;
import com.blamejared.crafttweaker.api.annotations.*;
import com.blamejared.crafttweaker.impl.util.*;
import com.blamejared.crafttweaker_annotations.annotations.*;
import org.openzen.zencode.java.*;

/**
* Denotes anything that is a builder.
* What did you expect?
*/
@ZenRegister
@Document("mods/contenttweaker/API/api/IIsBuilder")
@ZenCodeType.Name("mods.contenttweaker.api.IIsBuilder")
public interface IIsBuilder {

/**
* Instructs CoT to actually build whatever this builder is supposed to be building.
*
* @param resourceLocation The resource path to give this block
* @docParam resourceLocation "my_awesome_block"
*/
@ZenCodeType.Method
default void build(String name) {
build(new MCResourceLocation(ContentTweaker.MOD_ID, name));
default void build(String resourceLocation) {
build(new MCResourceLocation(ContentTweaker.MOD_ID, resourceLocation));
}

@ZenCodeType.Method
/**
* Instructs CoT to actually build whatever this builder is supposed to be building.
* This method is not recommended to be used, use the one that only accepts the path
*
* @param location The name to give this block
*/
void build(MCResourceLocation location);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
import com.blamejared.contenttweaker.api.*;
import com.blamejared.contenttweaker.blocks.*;
import com.blamejared.crafttweaker.api.annotations.*;
import com.blamejared.crafttweaker_annotations.annotations.*;
import org.openzen.zencode.java.*;

/**
* Denotes a special builder that is used for building special block types.
* Used in {@link BlockBuilder#withType}
*
* @docParam this new BlockBuilder().withType<BlockBuilderBasic>()
*/
@ZenRegister
@Document("mods/contenttweaker/API/block/BlockTypeBuilder")
@ZenCodeType.Name("mods.contenttweaker.block.BlockTypeBuilder")
public abstract class BlockTypeBuilder implements IIsBuilder {

protected final BlockBuilder blockBuilder;

protected BlockTypeBuilder(BlockBuilder blockBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
import com.blamejared.contenttweaker.api.*;
import com.blamejared.contenttweaker.items.*;
import com.blamejared.crafttweaker.api.annotations.*;
import com.blamejared.crafttweaker_annotations.annotations.*;
import org.openzen.zencode.java.*;

/**
* Denotes a special builder that is used for builing special item types.
* Used in {@link ItemBuilder#withType}
*
* @docParam this new ItemBuilder().withType<ItemBuilderBasic>()
*/
@ZenRegister
@Document("mods/contenttweaker/API/item/ItemTypeBuilder")
@ZenCodeType.Name("mods.contenttweaker.item.ItemTypeBuilder")
public abstract class ItemTypeBuilder implements IIsBuilder {

Expand Down
131 changes: 123 additions & 8 deletions src/main/java/com/blamejared/contenttweaker/blocks/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.blamejared.contenttweaker.api.*;
import com.blamejared.contenttweaker.api.blocks.*;
import com.blamejared.contenttweaker.blocks.types.basic.*;
import com.blamejared.contenttweaker.wrappers.*;
import com.blamejared.crafttweaker.api.*;
import com.blamejared.crafttweaker.api.annotations.*;
Expand All @@ -15,14 +16,28 @@

import java.lang.reflect.*;

/**
* The blockbuilder is used to... build blocks (you totally didn't see that one coming, right... right?).<br>
* Once you created it you can set various properties which will be outlined by the separate methods.
* <p>
* You can also change the block's type to create a more specialized form of block (e.g. stairs or Blocks that can be rotated in the same way logs can).
* To tell CoT that you want the block to appear ingame you need to call {@link #build(String)} and specify a valid resource location path.
*/
@ZenRegister
@ZenCodeType.Name("mods.contenttweaker.block.BlockBuilder")
@Document("mods/contenttweaker/block/BlockBuilder")
@Document("mods/contenttweaker/API/block/BlockBuilder")
public class BlockBuilder implements IIsBuilder {

private final Block.Properties blockProperties;
private final Item.Properties itemProperties;

/**
* Creates a new BlockBuilder.
* Remember that this will _not_ create a new block in the game, you need to call {@link #build(String)} for that.
*
* @param material The material this block will have
* @docParam material <blockmaterial:earth>
*/
@ZenCodeType.Constructor
public BlockBuilder(@ZenCodeType.Optional("<blockmaterial:iron>") MCMaterial material) {
blockProperties = Block.Properties.create(material.getInternal());
Expand All @@ -37,90 +52,184 @@ public Block.Properties getBlockProperties() {
return blockProperties;
}

/**
* Sets the maximum Stack size that this block can have when in your inventory.
* Will be 64 if unchanged.
*
* @param size The size to set.
* @return This builder, used for chaining
* @docParam size 16
*/
@ZenCodeType.Method
public BlockBuilder withMaxStackSize(int size) {
this.itemProperties.maxStackSize(size);
return this;
}

/**
* Sets the item group in which this block will appear
*
* @param group The group to set
* @return This builder, used for method chaining
* @docParam group <itemgroup:building_blocks>
*/
@ZenCodeType.Method
public BlockBuilder withItemGroup(MCItemGroup group) {
this.itemProperties.group(group.getInternal());
return this;
}

/**
* Allows you to set the rarity of this block.
*
* @param rarity The rarity
* @return This builder, used for method chaining
* @docParam rarity "UNCOMMON"
*/
@ZenCodeType.Method
public BlockBuilder withRarity(String rarity) {
this.itemProperties.rarity(Rarity.valueOf(rarity));
return this;
}

/**
* Instructs CoT that this block will does not block movement.
*
* @return This builder, used for chaining
*/
@ZenCodeType.Method
public BlockBuilder withoutMovementBlocking() {
this.blockProperties.doesNotBlockMovement();
return this;
}

/**
* Sets the slipperiness.
*
* @param slipperinessIn The value to set
* @return This builder, used for method chaining
* @docParam slipperinessIn 0.5f
*/
@ZenCodeType.Method
public BlockBuilder withSlipperiness(float slipperinessIn) {
blockProperties.slipperiness(slipperinessIn);
return this;
}

/**
* Sets the block's light value.
*
* @param lightValueIn The light level to set
* @return This builder, used for method chaining
* @docParam lightValueIn 15
*/
@ZenCodeType.Method
public BlockBuilder withLightValue(int lightValueIn) {
blockProperties.lightValue(lightValueIn);
return this;
}

/**
* Sets the block's hardness and resistance levels.
* Unlike the other method, this one allows you to set each property one to a separate value.
*
* @param hardnessIn The value to set for hardness
* @param resistanceIn The value to set for resistance.
* @return This builder, used for method chaining
* @docParam hardnessIn 0.5f
* @docParam resistanceIn 0.5f
*/
@ZenCodeType.Method
public BlockBuilder withHardnessAndResistance(float hardnessIn, float resistanceIn) {
blockProperties.hardnessAndResistance(hardnessIn, resistanceIn);
return this;
}

/**
* Sets the block's hardness and resistance levels.
* Unlike the other method, this one only accepts one parameter and will use that value for both properties.
*
* @param hardnessAndResistance The value to set for hardness and for resistance.
* @return This builder, used for method chaining
* @docParam hardnessAndResistance 0.5f
*/
@ZenCodeType.Method
public BlockBuilder withHardnessAndResistance(float hardnessAndResistance) {
blockProperties.hardnessAndResistance(hardnessAndResistance);
return this;
}

/*
This probably wont be needed
@ZenCodeType.Method
public BlockBuilder withTickRandomly() {
blockProperties.tickRandomly();
return this;
}
*/

@ZenCodeType.Method
public BlockBuilder withVariableOpacity() {
blockProperties.variableOpacity();
return this;
}

/**
* Sets the mining level required to mine this block
*
* @param harvestLevel The harvest level requried
* @return This builder, used for method chaining
* @docParam harvestLevel 3
*/
@ZenCodeType.Method
public BlockBuilder withHarvestLevel(int harvestLevel) {
blockProperties.harvestLevel(harvestLevel);
return this;
}

/**
* Sets the tool required to harvest this block
*
* @param harvestTool The tool type
* @return This builder, used for method chaining
* @docParam harvestTool <tooltype:shovel>
*/
@ZenCodeType.Method
public BlockBuilder withHarvestTool(MCToolType harvestTool) {
blockProperties.harvestTool(harvestTool.getInternal());
return this;
}

/**
* Will instruct CoT that this block will not have any loot entries.
* Currently this will still create a loot table entry, though it will be ignored by the game.
*
* @return This builder, used for method chaining
*/
@ZenCodeType.Method
public BlockBuilder withoutDrops() {
blockProperties.noDrops();
return this;
}

/**
* Will instruct CoT to override this block's loot table with the one of the block Provided.
* Currently this will still create a loot table entry, though it will be ignored by the game.
*
* @param blockIn The block whose loot table should be applied
* @return This builder, used for method chaining
* @docParam blockIn <block:minecraft:diamond>
*/
@ZenCodeType.Method
public BlockBuilder withLootFrom(MCBlock blockIn) {
blockProperties.lootFrom(blockIn.getInternal());
return this;
}

/**
* Sets the specific type of this block.
* After this method is called the builder's context will switch to the more provided type builder.
* That means that the methods of this builder will no longer be available, so any properties you wish to set should be set before you call this method.
*
* @param typeOfT Internally used by ZC to handle the Generic param
* @param <T> The Type of block that this should become
* @return A builder with the given block.
* @docParam T mods.contenttweaker.block.pillar.BlockBuilderPillarRotatable
*/
@ZenCodeType.Method
public <T extends BlockTypeBuilder> T withType(Class<T> typeOfT) {
try {
Expand All @@ -134,6 +243,12 @@ public <T extends BlockTypeBuilder> T withType(Class<T> typeOfT) {

@Override
public void build(MCResourceLocation location) {
//withType(BlockTypeSpecifiers.basic).applyToBuilder(location);
withType(BlockBuilderBasic.class).build(location);
}


@Override
public void build(String resourceLocation) {
IIsBuilder.super.build(resourceLocation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
import com.blamejared.contenttweaker.blocks.*;
import com.blamejared.crafttweaker.api.annotations.*;
import com.blamejared.crafttweaker.impl.util.*;
import com.blamejared.crafttweaker_annotations.annotations.*;
import org.openzen.zencode.java.*;

/**
* This builder builds the block type that is used by default in {@link BlockBuilder#build}
* This builder does not offer any special properties to set, you can only build it.
*
* @docParam this new BlockBuilder().withType<ItemBuilderBasic>()
*/
@ZenRegister
@ZenCodeType.Name("mods.contenttweaker.block.basic.BuilderBasic")
public class BuilderBasic extends BlockTypeBuilder {
@Document("mods/contenttweaker/API/block/basic/BlockBuilderBasic")
@ZenCodeType.Name("mods.contenttweaker.block.basic.BlockBuilderBasic")
public class BlockBuilderBasic extends BlockTypeBuilder {


public BuilderBasic(BlockBuilder builder) {
public BlockBuilderBasic(BlockBuilder builder) {
super(builder);
}

Expand Down

0 comments on commit 98fbdc1

Please sign in to comment.