-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2552: Add way to use resource conditions for block loot table da…
…tagen (#2823)
- Loading branch information
1 parent
2facd44
commit 06937c4
Showing
7 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
.../src/main/java/net/fabricmc/fabric/api/datagen/v1/loot/FabricBlockLootTableGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.api.datagen.v1.loot; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
import net.minecraft.data.server.loottable.BlockLootTableGenerator; | ||
|
||
import net.fabricmc.fabric.api.resource.conditions.v1.ConditionJsonProvider; | ||
import net.fabricmc.fabric.impl.datagen.loot.ConditionBlockLootTableGenerator; | ||
|
||
/** | ||
* Fabric-provided extensions for {@link BlockLootTableGenerator}. | ||
* | ||
* <p>Note: This interface is automatically implemented via Mixin and interface injection. | ||
*/ | ||
public interface FabricBlockLootTableGenerator { | ||
/** | ||
* Return a new generator that applies the specified conditions to any loot table it receives, | ||
* and then forwards the loot tables to this generator. | ||
*/ | ||
default BlockLootTableGenerator withConditions(ConditionJsonProvider... conditions) { | ||
Preconditions.checkArgument(conditions.length > 0, "Must add at least one condition."); | ||
|
||
return new ConditionBlockLootTableGenerator((BlockLootTableGenerator) this, conditions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...src/main/java/net/fabricmc/fabric/impl/datagen/loot/ConditionBlockLootTableGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.impl.datagen.loot; | ||
|
||
import java.util.Collections; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.data.server.loottable.BlockLootTableGenerator; | ||
import net.minecraft.loot.LootTable; | ||
import net.minecraft.resource.featuretoggle.FeatureFlags; | ||
|
||
import net.fabricmc.fabric.api.resource.conditions.v1.ConditionJsonProvider; | ||
import net.fabricmc.fabric.impl.datagen.FabricDataGenHelper; | ||
|
||
public class ConditionBlockLootTableGenerator extends BlockLootTableGenerator { | ||
private final BlockLootTableGenerator parent; | ||
private final ConditionJsonProvider[] conditions; | ||
|
||
public ConditionBlockLootTableGenerator(BlockLootTableGenerator parent, ConditionJsonProvider[] conditions) { | ||
super(Collections.emptySet(), FeatureFlags.FEATURE_MANAGER.getFeatureSet()); | ||
|
||
this.parent = parent; | ||
this.conditions = conditions; | ||
} | ||
|
||
@Override | ||
public void generate() { | ||
throw new UnsupportedOperationException("generate() should not be called."); | ||
} | ||
|
||
@Override | ||
public void addDrop(Block block, LootTable.Builder lootTable) { | ||
FabricDataGenHelper.addConditions(lootTable, conditions); | ||
this.parent.addDrop(block, lootTable); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...v1/src/main/java/net/fabricmc/fabric/mixin/datagen/loot/BlockLootTableGeneratorMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.mixin.datagen.loot; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
import net.minecraft.data.server.loottable.BlockLootTableGenerator; | ||
|
||
import net.fabricmc.fabric.api.datagen.v1.loot.FabricBlockLootTableGenerator; | ||
|
||
@Mixin(BlockLootTableGenerator.class) | ||
public class BlockLootTableGeneratorMixin implements FabricBlockLootTableGenerator { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters