-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
234 additions
and
93 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/net/fabricmc/fabric/api/events/LootTableLoadingCallback.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,33 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018 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.events; | ||
|
||
import net.fabricmc.fabric.api.loot.FabricLootSupplier; | ||
import net.fabricmc.fabric.util.HandlerArray; | ||
import net.fabricmc.fabric.util.HandlerRegistry; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
/** | ||
* An event handler that is called when loot tables are loaded. | ||
* Use {@link #REGISTRY} to register instances. | ||
*/ | ||
@FunctionalInterface | ||
public interface LootTableLoadingCallback extends BiConsumer<Identifier, FabricLootSupplier> { | ||
final HandlerRegistry<LootTableLoadingCallback> REGISTRY = new HandlerArray<>(LootTableLoadingCallback.class); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/net/fabricmc/fabric/api/loot/FabricLootPool.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,44 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018 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.loot; | ||
|
||
import net.minecraft.world.loot.LootPool; | ||
import net.minecraft.world.loot.LootTableRange; | ||
import net.minecraft.world.loot.UniformLootTableRange; | ||
import net.minecraft.world.loot.condition.LootCondition; | ||
import net.minecraft.world.loot.entry.LootEntry; | ||
import net.minecraft.world.loot.function.LootFunction; | ||
|
||
/** | ||
* An interface implemented by all {@code net.minecraft.world.loot.LootPool} instances when | ||
* Fabric API is present. Contains accessors for various fields. | ||
*/ | ||
public interface FabricLootPool { | ||
default LootPool toVanilla() { | ||
return (LootPool) this; | ||
} | ||
LootEntry[] getEntries(); | ||
void setEntries(LootEntry[] entries); | ||
LootCondition[] getConditions(); | ||
void setConditions(LootCondition[] conditions); | ||
LootFunction[] getFunctions(); | ||
void setFunctions(LootFunction[] entries); | ||
LootTableRange getRolls(); | ||
void setRolls(LootTableRange rolls); | ||
UniformLootTableRange getBonusRolls(); | ||
void setBonusRolls(UniformLootTableRange bonusRolls); | ||
} |
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
23 changes: 0 additions & 23 deletions
23
src/main/java/net/fabricmc/fabric/impl/loot/LootSupplierHooks.java
This file was deleted.
Oops, something went wrong.
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
70 changes: 70 additions & 0 deletions
70
src/main/java/net/fabricmc/fabric/mixin/loot/MixinLootPool.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,70 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018 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.loot; | ||
|
||
import net.fabricmc.fabric.api.loot.FabricLootPool; | ||
import net.minecraft.world.loot.LootPool; | ||
import net.minecraft.world.loot.LootTableRange; | ||
import net.minecraft.world.loot.UniformLootTableRange; | ||
import net.minecraft.world.loot.condition.LootCondition; | ||
import net.minecraft.world.loot.entry.LootEntry; | ||
import net.minecraft.world.loot.function.LootFunction; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(LootPool.class) | ||
public interface MixinLootPool extends FabricLootPool { | ||
@Accessor | ||
@Override | ||
LootEntry[] getEntries(); | ||
|
||
@Accessor | ||
@Override | ||
LootCondition[] getConditions(); | ||
|
||
@Accessor | ||
@Override | ||
LootFunction[] getFunctions(); | ||
|
||
@Accessor | ||
@Override | ||
LootTableRange getRolls(); | ||
|
||
@Accessor | ||
@Override | ||
UniformLootTableRange getBonusRolls(); | ||
|
||
@Accessor | ||
@Override | ||
void setEntries(LootEntry[] entries); | ||
|
||
@Accessor | ||
@Override | ||
void setConditions(LootCondition[] conditions); | ||
|
||
@Accessor | ||
@Override | ||
void setFunctions(LootFunction[] entries); | ||
|
||
@Accessor | ||
@Override | ||
void setRolls(LootTableRange rolls); | ||
|
||
@Accessor | ||
@Override | ||
void setBonusRolls(UniformLootTableRange bonusRolls); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018 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.loot; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
import net.fabricmc.fabric.api.events.LootTableLoadingCallback; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.world.loot.ConstantLootTableRange; | ||
import net.minecraft.world.loot.LootPool; | ||
import net.minecraft.world.loot.condition.SurvivesExplosionLootCondition; | ||
import net.minecraft.world.loot.entry.ItemEntry; | ||
|
||
import java.util.Arrays; | ||
|
||
public class LootTableMod implements ModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
LootTableLoadingCallback.REGISTRY.register((id, supplier) -> { | ||
if ("minecraft:blocks/dirt".equals(id.toString())) { | ||
LootPool[] pools = Arrays.copyOf(supplier.getPools(), supplier.getPools().length + 1); | ||
pools[pools.length - 1] = LootPool.create() | ||
.withEntry(ItemEntry.builder(Items.FEATHER)) | ||
.withRolls(ConstantLootTableRange.create(1)) | ||
.withCondition(SurvivesExplosionLootCondition.method_871()) | ||
.build(); | ||
|
||
supplier.setPools(pools); | ||
} | ||
}); | ||
} | ||
} |