Skip to content

Commit

Permalink
Provide no block item warning in base class
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner committed Aug 1, 2022
1 parent 01ae1aa commit d6d3d60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
@ZenCodeType.Name(ContentTweakerVanillaConstants.BLOCK_BUILDER_PACKAGE + ".Basic")
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID)
public final class BasicBlockBuilder extends BlockBuilder<BasicBlockBuilder> {
private static final String WARN = "Unable to automatically generate loot table for block '%s' because the automatic block item has been disabled: an empty one will be generated instead";

public BasicBlockBuilder(final BiFunction<ObjectHolder<? extends Block>, Consumer<ResourceManager>, BlockReference> registrationManager) {
super(registrationManager);
}
Expand All @@ -50,8 +48,10 @@ public void provideResources(final ResourceLocation name, final ResourceManager

if (flags.generateLootTable()) {
final ResourceFragment cotData = manager.fragment(StandardResourceFragmentKeys.CONTENT_TWEAKER_DATA);

// TODO("Maybe include this in BlockBuilder")
this.selfLootTable(name, flags)
.or(() -> this.emptyTable(name, WARN::formatted))
.or(() -> this.emptyTable(name, LOOT_GEN_FAILURE_DUE_TO_NO_ITEM::formatted))
.ifPresent(it -> cotData.provideFixed(PathHelper.blockLootTable(name), it, LootTable.SERIALIZER));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@
public abstract class BlockBuilder<T extends BlockBuilder<T>> {
protected record GenerateFlags(boolean generateLootTable, boolean generateBlockItem) {}

protected static final String LOOT_GEN_FAILURE_DUE_TO_NO_ITEM =
"Unable to automatically generate loot table for block '%s' because the automatic block item has been disabled: an empty one will be generated instead";

// Compare with equality
private static final ResourceLocation DO_NOT_CLONE_DROPS = ContentTweakerConstants.rl("do_not_clone_drops");
private static final ResourceLocation DO_NOT_DROP_DROPS = ContentTweakerConstants.rl("do_not_drop_drops");
private static final ResourceLocation FORCE_GENERATION_OF_DROPS = ContentTweakerConstants.rl("force_generation_of_drops");

private final BiFunction<ObjectHolder<? extends Block>, Consumer<ResourceManager>, BlockReference> registrationManager;

Expand Down Expand Up @@ -242,6 +246,11 @@ public T dropsNormally() {
return this.cloningProperties != null? this.dropsFrom(DO_NOT_CLONE_DROPS) : this.self();
}

@ZenCodeType.Method("dropsItselfRegardless")
public T dropsItselfRegardless() {
return this.dropsFrom(FORCE_GENERATION_OF_DROPS);
}

@ZenCodeType.Method("occludes")
public T occludes(final boolean occlude) {
this.occlude = occlude;
Expand Down Expand Up @@ -319,7 +328,7 @@ protected final Optional<LootTable> emptyTable(final ResourceLocation name, fina

protected final Optional<LootTable> selfLootTable(final ResourceLocation name, final GenerateFlags flags) {
Objects.requireNonNull(name);
if (!Objects.requireNonNull(flags).generateBlockItem()) {
if (!Objects.requireNonNull(flags).generateBlockItem() && this.drops != FORCE_GENERATION_OF_DROPS) {
return Optional.empty();
}
final LootTable table = LootTable.ofBlock()
Expand Down Expand Up @@ -456,7 +465,7 @@ private BlockBehaviour.Properties make(
if (jump != null) {
properties.jumpFactor(jump);
}
if (drops != null && drops != DO_NOT_CLONE_DROPS) {
if (drops != null && drops != DO_NOT_CLONE_DROPS && drops != FORCE_GENERATION_OF_DROPS) {
if (drops == DO_NOT_DROP_DROPS) {
properties.noDrops();
} else {
Expand Down

0 comments on commit d6d3d60

Please sign in to comment.