More hooks

This commit is contained in:
shedaniel
2020-11-07 22:53:20 +08:00
parent fe9e0383f6
commit d2ab1c5110
27 changed files with 608 additions and 26 deletions

View File

@@ -24,6 +24,14 @@ import java.lang.reflect.Modifier;
public final class ArchitecturyPopulator {
private ArchitecturyPopulator() {}
public static void populate() {
try {
populate(Class.forName(Thread.currentThread().getStackTrace()[2].getClassName()));
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
public static void populate(Object o) {
try {
if (o instanceof Class) {

View File

@@ -20,15 +20,33 @@ import me.shedaniel.architectury.event.Event;
import me.shedaniel.architectury.event.EventFactory;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
public interface EntityEvent {
/**
* Invoked before LivingEntity#die, equivalent to forge's {@code LivingDeathEvent}.
*/
Event<LivingDeath> LIVING_DEATH = EventFactory.createInteractionResult(LivingDeath.class);
/**
* Invoked before LivingEntity#hurt, equivalent to forge's {@code LivingAttackEvent}.
*/
Event<LivingAttack> LIVING_ATTACK = EventFactory.createInteractionResult(LivingAttack.class);
/**
* Invoked before entity is added to a world, equivalent to forge's {@code EntityJoinWorldEvent}.
*/
Event<Add> ADD = EventFactory.createInteractionResult(Add.class);
interface LivingDeath {
InteractionResult die(LivingEntity entity, DamageSource source);
}
interface LivingAttack {
InteractionResult attack(LivingEntity entity, DamageSource source, float amount);
}
interface Add {
InteractionResult add(Entity entity, Level world);
}
}

View File

@@ -23,6 +23,10 @@ import net.fabricmc.api.Environment;
import net.minecraft.advancements.Advancement;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
public interface PlayerEvent {
Event<PlayerJoin> PLAYER_JOIN = EventFactory.createLoop(PlayerJoin.class);
@@ -33,6 +37,9 @@ public interface PlayerEvent {
@Environment(EnvType.CLIENT) Event<ClientPlayerRespawn> CLIENT_PLAYER_RESPAWN = EventFactory.createLoop(ClientPlayerRespawn.class);
Event<PlayerAdvancement> PLAYER_ADVANCEMENT = EventFactory.createLoop(PlayerAdvancement.class);
Event<PlayerClone> PLAYER_CLONE = EventFactory.createLoop(PlayerClone.class);
Event<SmeltItem> SMELT_ITEM = EventFactory.createLoop(SmeltItem.class);
Event<PickupItemPredicate> PICKUP_ITEM_PRE = EventFactory.createInteractionResult(PickupItemPredicate.class);
Event<PickupItem> PICKUP_ITEM_POST = EventFactory.createLoop(PickupItem.class);
interface PlayerJoin {
void join(ServerPlayer player);
@@ -54,6 +61,18 @@ public interface PlayerEvent {
void award(ServerPlayer player, Advancement advancement);
}
interface SmeltItem {
void smelt(Player player, ItemStack smelted);
}
interface PickupItemPredicate {
InteractionResult canPickup(Player player, ItemEntity entity, ItemStack smelted);
}
interface PickupItem {
void pickup(Player player, ItemEntity entity, ItemStack smelted);
}
@Environment(EnvType.CLIENT)
interface ClientPlayerJoin {
void join(LocalPlayer player);

View File

@@ -0,0 +1,58 @@
package me.shedaniel.architectury.registry;
import me.shedaniel.architectury.ArchitecturyPopulator;
import me.shedaniel.architectury.Populatable;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import java.util.function.Function;
public abstract class BlockProperties extends BlockBehaviour.Properties implements BlockPropertiesExtension {
@Populatable
private static final Impl IMPL = null;
public BlockProperties(Material material, Function<BlockState, MaterialColor> function) {
super(material, function);
}
public static BlockProperties of(Material material) {
return of(material, material.getColor());
}
public static BlockProperties of(Material material, DyeColor color) {
return of(material, color.getMaterialColor());
}
public static BlockProperties of(Material material, MaterialColor color) {
return IMPL.of(material, color);
}
public static BlockProperties of(Material material, Function<BlockState, MaterialColor> color) {
return IMPL.of(material, color);
}
public static BlockProperties copy(BlockBehaviour block) {
return IMPL.copy(block);
}
public static BlockProperties copy(BlockBehaviour.Properties properties) {
return IMPL.copy(properties);
}
public interface Impl {
BlockProperties of(Material material, MaterialColor color);
BlockProperties of(Material material, Function<BlockState, MaterialColor> color);
BlockProperties copy(BlockBehaviour block);
BlockProperties copy(BlockBehaviour.Properties properties);
}
static {
ArchitecturyPopulator.populate();
}
}

View File

@@ -0,0 +1,9 @@
package me.shedaniel.architectury.registry;
public interface BlockPropertiesExtension {
default BlockProperties tool(ToolType type) {
return tool(type, 0);
}
BlockProperties tool(ToolType type, int level);
}

View File

@@ -0,0 +1,55 @@
package me.shedaniel.architectury.registry;
import me.shedaniel.architectury.Populatable;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import java.util.function.Supplier;
public final class ToolType {
public static final ToolType PICKAXE = create("pickaxe", ToolType::pickaxeTag);
public static final ToolType AXE = create("axe", ToolType::axeTag);
public static final ToolType HOE = create("hoe", ToolType::hoeTag);
public static final ToolType SHOVEL = create("shovel", ToolType::shovelTag);
@Populatable
private static final Impl IMPL = null;
private static Tag<Item> pickaxeTag() {
return IMPL.pickaxeTag();
}
private static Tag<Item> axeTag() {
return IMPL.axeTag();
}
private static Tag<Item> hoeTag() {
return IMPL.hoeTag();
}
private static Tag<Item> shovelTag() {
return IMPL.shovelTag();
}
public final String forgeName;
public final Supplier<Tag<Item>> fabricTag;
private Object obj;
private ToolType(String forgeName, Supplier<Tag<Item>> fabricTag) {
this.forgeName = forgeName;
this.fabricTag = fabricTag;
}
public static ToolType create(String forgeName, Supplier<Tag<Item>> fabricTag) {
return new ToolType(forgeName, fabricTag);
}
public interface Impl {
Tag<Item> pickaxeTag();
Tag<Item> axeTag();
Tag<Item> hoeTag();
Tag<Item> shovelTag();
}
}

View File

@@ -0,0 +1,2 @@
accessWidener v1 named
accessible method net/minecraft/world/level/block/state/BlockBehaviour$Properties <init> (Lnet/minecraft/world/level/material/Material;Ljava/util/function/Function;)V

View File

@@ -2,5 +2,6 @@
"_comment": "This file is here to make fabric loader load this on the Knot classloader.",
"schemaVersion": 1,
"id": "architectury-common",
"version": "0.0.1"
"version": "0.0.1",
"accessWidener": "architectury-common.accessWidener"
}