Update to 24w40a

This commit is contained in:
shedaniel
2024-10-06 05:07:39 +08:00
parent a14036d12b
commit fe43bbddc9
73 changed files with 377 additions and 838 deletions

View File

@@ -8,7 +8,7 @@ buildscript {
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false
id "org.cadixdev.licenser" version "0.6.1"
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
id "maven-publish"

View File

@@ -23,11 +23,11 @@ import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.platform.Platform;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
@@ -78,7 +78,7 @@ public abstract class ArchitecturyFlowingFluid extends FlowingFluid {
}
@Override
protected boolean canConvertToSource(Level level) {
protected boolean canConvertToSource(ServerLevel level) {
return attributes.canConvertToSource();
}

View File

@@ -24,9 +24,9 @@ import net.minecraft.core.Direction;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.block.DispenserBlock;
@@ -50,7 +50,7 @@ public class ArchitecturySpawnEggItem extends SpawnEggItem {
EntityType<?> entityType = ((SpawnEggItem) stack.getItem()).getType(stack);
try {
entityType.spawn(source.level(), stack, null, source.pos().relative(direction), MobSpawnType.DISPENSER, direction != Direction.UP, false);
entityType.spawn(source.level(), stack, null, source.pos().relative(direction), EntitySpawnReason.DISPENSER, direction != Direction.UP, false);
} catch (Exception var6) {
LOGGER.error("Error while dispensing spawn egg from dispenser at {}", source.pos(), var6);
return ItemStack.EMPTY;

View File

@@ -19,8 +19,6 @@
package dev.architectury.event;
import net.minecraft.world.InteractionResultHolder;
/**
* A result from an event, determines if the event should continue to other listeners,
* determines the outcome of the event, and provides extra result for the outcome.
@@ -170,13 +168,4 @@ public class CompoundEventResult<T> {
public T object() {
return object;
}
/**
* Returns the Minecraft-facing result, however ignores {@link #interruptsFurtherEvaluation()}.
*
* @return the Minecraft-facing result
*/
public InteractionResultHolder<T> asMinecraft() {
return new InteractionResultHolder<>(result.asMinecraft(), object);
}
}

View File

@@ -23,6 +23,7 @@ import com.google.common.reflect.AbstractInvocationHandler;
import dev.architectury.annotations.ForgeEvent;
import dev.architectury.annotations.ForgeEventCancellable;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.world.InteractionResult;
import org.jetbrains.annotations.ApiStatus;
import java.lang.invoke.MethodHandles;
@@ -110,6 +111,28 @@ public final class EventFactory {
}));
}
@SafeVarargs
public static <T> Event<T> createInteractionResult(T... typeGetter) {
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");
return createInteractionResult((Class<T>) typeGetter.getClass().getComponentType());
}
@SuppressWarnings("UnstableApiUsage")
public static <T> Event<T> createInteractionResult(Class<T> clazz) {
return of(listeners -> (T) Proxy.newProxyInstance(EventFactory.class.getClassLoader(), new Class[]{clazz}, new AbstractInvocationHandler() {
@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
for (var listener : listeners) {
var result = (InteractionResult) Objects.requireNonNull(invokeMethod(listener, method, args));
if (result != InteractionResult.PASS) {
return result;
}
}
return InteractionResult.PASS;
}
}));
}
@SafeVarargs
public static <T> Event<Consumer<T>> createConsumerLoop(T... typeGetter) {
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");

View File

@@ -23,20 +23,47 @@ import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.network.protocol.game.ClientboundRecipeBookAddPacket;
import net.minecraft.world.item.crafting.RecipeAccess;
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
import org.jetbrains.annotations.ApiStatus;
import java.util.List;
@Environment(EnvType.CLIENT)
public interface ClientRecipeUpdateEvent {
/**
* @see ClientRecipeUpdateEvent#update(RecipeManager)
* @see ClientRecipeUpdateEvent#update(RecipeAccess)
*/
Event<ClientRecipeUpdateEvent> EVENT = EventFactory.createLoop();
/**
* @see ClientRecipeUpdateEvent.Add#add(RecipeAccess, List)
*/
@ApiStatus.Experimental
Event<Add> ADD = EventFactory.createLoop();
/**
* @see ClientRecipeUpdateEvent.Remove#remove(RecipeAccess, List)
*/
@ApiStatus.Experimental
Event<Remove> REMOVE = EventFactory.createLoop();
/**
* Invoked when the client has received an updated list of recipes from the server.
* Equivalent to Forge's {@code RecipesUpdatedEvent} event.
*
* @param recipeManager The recipe manager.
* @param recipeAccess The recipe access.
*/
void update(RecipeManager recipeManager);
void update(RecipeAccess recipeAccess);
@ApiStatus.Experimental
interface Add {
void add(RecipeAccess recipeAccess, List<ClientboundRecipeBookAddPacket.Entry> entries);
}
@ApiStatus.Experimental
interface Remove {
void remove(RecipeAccess recipeAccess, List<RecipeDisplayId> ids);
}
}

View File

@@ -1,47 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.event.events.client;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.server.packs.resources.ResourceProvider;
import java.util.function.Consumer;
@Environment(EnvType.CLIENT)
@FunctionalInterface
public interface ClientReloadShadersEvent {
/**
* Invoked when client reloads shaders.
*
* @see net.minecraft.client.renderer.GameRenderer#reloadShaders(ResourceProvider)
*/
Event<ClientReloadShadersEvent> EVENT = EventFactory.createLoop();
void reload(ResourceProvider provider, ShadersSink sink);
@FunctionalInterface
interface ShadersSink {
void registerShader(ShaderInstance shader, Consumer<ShaderInstance> callback);
}
}

View File

@@ -49,10 +49,6 @@ public interface ClientTooltipEvent {
* @see RenderModifyPosition#renderTooltip(GuiGraphics, PositionContext)
*/
Event<RenderModifyPosition> RENDER_MODIFY_POSITION = EventFactory.createLoop();
/**
* @see RenderModifyColor#renderTooltip(GuiGraphics, int, int, ColorContext)
*/
Event<RenderModifyColor> RENDER_MODIFY_COLOR = EventFactory.createLoop();
static AdditionalContexts additionalContexts() {
return TooltipAdditionalContextsImpl.get();
@@ -107,19 +103,6 @@ public interface ClientTooltipEvent {
void renderTooltip(GuiGraphics graphics, PositionContext context);
}
@Environment(EnvType.CLIENT)
interface RenderModifyColor {
/**
* Event to manipulate the color of the tooltip.
*
* @param graphics The graphics context.
* @param x The x-coordinate of the tooltip.
* @param y The y-coordinate of the tooltip.
* @param context The current color context.
*/
void renderTooltip(GuiGraphics graphics, int x, int y, ColorContext context);
}
@Environment(EnvType.CLIENT)
interface PositionContext {
int getTooltipX();
@@ -130,19 +113,4 @@ public interface ClientTooltipEvent {
void setTooltipY(int y);
}
@Environment(EnvType.CLIENT)
interface ColorContext {
int getBackgroundColor();
void setBackgroundColor(int color);
int getOutlineGradientTopColor();
void setOutlineGradientTopColor(int color);
int getOutlineGradientBottomColor();
void setOutlineGradientBottomColor(int color);
}
}

View File

@@ -28,11 +28,11 @@ import org.jetbrains.annotations.Nullable;
public interface ChunkEvent {
/**
* @see SaveData#save(ChunkAccess, ServerLevel, CompoundTag)
* @see SaveData#save(ChunkAccess, ServerLevel)
*/
Event<SaveData> SAVE_DATA = EventFactory.createLoop();
/**
* @see LoadData#load(ChunkAccess, ServerLevel, CompoundTag)
* @see LoadData#load(ChunkAccess, ServerLevel)
*/
Event<LoadData> LOAD_DATA = EventFactory.createLoop();
@@ -44,9 +44,8 @@ public interface ChunkEvent {
*
* @param chunk The chunk that is saved.
* @param level The level the chunk is in.
* @param nbt The chunk data that is written to the save file.
*/
void save(ChunkAccess chunk, ServerLevel level, CompoundTag nbt);
void save(ChunkAccess chunk, ServerLevel level);
}
interface LoadData {
@@ -57,8 +56,7 @@ public interface ChunkEvent {
*
* @param chunk The chunk that is loaded.
* @param level The level the chunk is in, may be {@code null}.
* @param nbt The chunk data that was read from the save file.
*/
void load(ChunkAccess chunk, @Nullable ServerLevel level, CompoundTag nbt);
void load(ChunkAccess chunk, @Nullable ServerLevel level);
}
}

View File

@@ -22,11 +22,10 @@ package dev.architectury.event.events.common;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BaseSpawner;
@@ -44,7 +43,7 @@ public interface EntityEvent {
*/
Event<LivingHurt> LIVING_HURT = EventFactory.createEventResult();
/**
* @see LivingCheckSpawn#canSpawn(LivingEntity, LevelAccessor, double, double, double, MobSpawnType, BaseSpawner)
* @see LivingCheckSpawn#canSpawn(LivingEntity, LevelAccessor, double, double, double, EntitySpawnReason, BaseSpawner)
*/
Event<LivingCheckSpawn> LIVING_CHECK_SPAWN = EventFactory.createEventResult();
/**
@@ -102,10 +101,10 @@ public interface EntityEvent {
* @param z The z-coordinate the spawn position.
* @param type The source of spawning.
* @param spawner The spawner. Can be {@code null}.
* @return A {@link InteractionResultHolder} determining the outcome of the event,
* @return A {@link EventResult} determining the outcome of the event,
* if an outcome is set, the vanilla result is overridden.
*/
EventResult canSpawn(LivingEntity entity, LevelAccessor world, double x, double y, double z, MobSpawnType type, @Nullable BaseSpawner spawner);
EventResult canSpawn(LivingEntity entity, LevelAccessor world, double x, double y, double z, EntitySpawnReason type, @Nullable BaseSpawner spawner);
}
interface Add {

View File

@@ -19,16 +19,15 @@
package dev.architectury.event.events.common;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
@@ -36,15 +35,15 @@ public interface InteractionEvent {
/**
* @see LeftClickBlock#click(Player, InteractionHand, BlockPos, Direction)
*/
Event<LeftClickBlock> LEFT_CLICK_BLOCK = EventFactory.createEventResult();
Event<LeftClickBlock> LEFT_CLICK_BLOCK = EventFactory.createInteractionResult();
/**
* @see RightClickBlock#click(Player, InteractionHand, BlockPos, Direction)
*/
Event<RightClickBlock> RIGHT_CLICK_BLOCK = EventFactory.createEventResult();
Event<RightClickBlock> RIGHT_CLICK_BLOCK = EventFactory.createInteractionResult();
/**
* @see RightClickItem#click(Player, InteractionHand)
*/
Event<RightClickItem> RIGHT_CLICK_ITEM = EventFactory.createCompoundEventResult();
Event<RightClickItem> RIGHT_CLICK_ITEM = EventFactory.createInteractionResult();
/**
* @see ClientLeftClickAir#click(Player, InteractionHand)
*/
@@ -60,7 +59,7 @@ public interface InteractionEvent {
/**
* @see FarmlandTrample#trample(Level, BlockPos, BlockState, float, Entity)
*/
Event<FarmlandTrample> FARMLAND_TRAMPLE = EventFactory.createEventResult();
Event<FarmlandTrample> FARMLAND_TRAMPLE = EventFactory.createInteractionResult();
interface RightClickBlock {
/**
@@ -71,10 +70,10 @@ public interface InteractionEvent {
* @param hand The hand that is used.
* @param pos The position of the block in the level.
* @param face The face of the block clicked.
* @return A {@link EventResult} determining the outcome of the event,
* @return A {@link InteractionResult} determining the outcome of the event,
* the action may be cancelled by the result.
*/
EventResult click(Player player, InteractionHand hand, BlockPos pos, Direction face);
InteractionResult click(Player player, InteractionHand hand, BlockPos pos, Direction face);
}
interface LeftClickBlock {
@@ -86,10 +85,10 @@ public interface InteractionEvent {
* @param hand The hand that is used.
* @param pos The position of the block in the level. Use {@link Player#getCommandSenderWorld()} to get the level.
* @param face The face of the block clicked.
* @return A {@link EventResult} determining the outcome of the event,
* @return A {@link InteractionResult} determining the outcome of the event,
* the action may be cancelled by the result.
*/
EventResult click(Player player, InteractionHand hand, BlockPos pos, Direction face);
InteractionResult click(Player player, InteractionHand hand, BlockPos pos, Direction face);
}
interface RightClickItem {
@@ -99,10 +98,10 @@ public interface InteractionEvent {
*
* @param player The player right clicking the block.
* @param hand The hand that is used.
* @return A {@link EventResult} determining the outcome of the event,
* @return A {@link InteractionResult} determining the outcome of the event,
* the action may be cancelled by the result.
*/
CompoundEventResult<ItemStack> click(Player player, InteractionHand hand);
InteractionResult click(Player player, InteractionHand hand);
}
interface ClientRightClickAir {
@@ -153,9 +152,9 @@ public interface InteractionEvent {
* @param state The state of the block.
* @param distance The distance of the player to the block.
* @param entity The entity trampling.
* @return A {@link EventResult} determining the outcome of the event,
* @return A {@link InteractionResult} determining the outcome of the event,
* the action may be cancelled by the result.
*/
EventResult trample(Level world, BlockPos pos, BlockState state, float distance, Entity entity);
InteractionResult trample(Level world, BlockPos pos, BlockState state, float distance, Entity entity);
}
}

View File

@@ -19,7 +19,6 @@
package dev.architectury.event.events.common;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
@@ -28,6 +27,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.Container;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
@@ -94,7 +94,7 @@ public interface PlayerEvent {
/**
* @see FillBucket#fill(Player, Level, ItemStack, HitResult)
*/
Event<FillBucket> FILL_BUCKET = EventFactory.createCompoundEventResult();
Event<FillBucket> FILL_BUCKET = EventFactory.createInteractionResult();
/**
* @see AttackEntity#attack(Player, Level, Entity, InteractionHand, EntityHitResult)
*/
@@ -265,9 +265,9 @@ public interface PlayerEvent {
* @param level The level the player is in.
* @param stack The bucket stack.
* @param target The target which the player has aimed at.
* @return A {@link CompoundEventResult} determining the outcome of the event.
* @return A {@link InteractionResult} determining the outcome of the event.
*/
CompoundEventResult<ItemStack> fill(Player player, Level level, ItemStack stack, @Nullable HitResult target);
InteractionResult fill(Player player, Level level, ItemStack stack, @Nullable HitResult target);
}
interface AttackEntity {

View File

@@ -1,33 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.extensions.injected;
import dev.architectury.hooks.item.food.FoodPropertiesHooks;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.food.FoodProperties;
import java.util.function.Supplier;
public interface InjectedFoodPropertiesBuilderExtension {
default FoodProperties.Builder arch$effect(Supplier<? extends MobEffectInstance> effectSupplier, float chance) {
FoodPropertiesHooks.effect((FoodProperties.Builder) this, effectSupplier, chance);
return (FoodProperties.Builder) this;
}
}

View File

@@ -1,37 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.hooks.item.food;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.food.FoodProperties;
import java.util.function.Supplier;
public final class FoodPropertiesHooks {
private FoodPropertiesHooks() {
}
@ExpectPlatform
public static void effect(FoodProperties.Builder builder,
Supplier<? extends MobEffectInstance> effectSupplier, float chance) {
throw new AssertionError();
}
}

View File

@@ -1,41 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.hooks.level;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.phys.Vec3;
/**
* @deprecated no longer needed.
*/
@Deprecated(forRemoval = true)
public final class ExplosionHooks {
private ExplosionHooks() {
}
/**
* @deprecated no longer needed.
* @see Explosion#center()
*/
@Deprecated(forRemoval = true)
public static Vec3 getPosition(Explosion explosion) {
return explosion.center();
}
}

View File

@@ -349,8 +349,8 @@ public final class BiomeHooks {
}
@Override
public Iterable<Holder<ConfiguredWorldCarver<?>>> getCarvers(GenerationStep.Carving carving) {
return settings.getCarvers(carving);
public Iterable<Holder<ConfiguredWorldCarver<?>>> getCarvers() {
return settings.getCarvers();
}
@Override

View File

@@ -29,7 +29,7 @@ import org.jetbrains.annotations.ApiStatus;
import java.util.List;
public interface GenerationProperties {
Iterable<Holder<ConfiguredWorldCarver<?>>> getCarvers(GenerationStep.Carving carving);
Iterable<Holder<ConfiguredWorldCarver<?>>> getCarvers();
Iterable<Holder<PlacedFeature>> getFeatures(GenerationStep.Decoration decoration);
@@ -41,13 +41,13 @@ public interface GenerationProperties {
@ApiStatus.Experimental
Mutable addFeature(GenerationStep.Decoration decoration, ResourceKey<PlacedFeature> feature);
Mutable addCarver(GenerationStep.Carving carving, Holder<ConfiguredWorldCarver<?>> feature);
Mutable addCarver(Holder<ConfiguredWorldCarver<?>> feature);
@ApiStatus.Experimental
Mutable addCarver(GenerationStep.Carving carving, ResourceKey<ConfiguredWorldCarver<?>> feature);
Mutable addCarver(ResourceKey<ConfiguredWorldCarver<?>> feature);
Mutable removeFeature(GenerationStep.Decoration decoration, ResourceKey<PlacedFeature> feature);
Mutable removeCarver(GenerationStep.Carving carving, ResourceKey<ConfiguredWorldCarver<?>> feature);
Mutable removeCarver(ResourceKey<ConfiguredWorldCarver<?>> feature);
}
}

View File

@@ -1,69 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.impl;
import dev.architectury.event.events.client.ClientTooltipEvent;
import org.jetbrains.annotations.ApiStatus;
@ApiStatus.Internal
public class TooltipEventColorContextImpl implements ClientTooltipEvent.ColorContext {
public static final ThreadLocal<TooltipEventColorContextImpl> CONTEXT = ThreadLocal.withInitial(TooltipEventColorContextImpl::new);
private int backgroundColor;
private int outlineGradientTopColor;
private int outlineGradientBottomColor;
public TooltipEventColorContextImpl reset() {
this.backgroundColor = 0xf0100010;
this.outlineGradientTopColor = 0x505000ff;
this.outlineGradientBottomColor = 0x5028007f;
return this;
}
@Override
public int getBackgroundColor() {
return backgroundColor;
}
@Override
public void setBackgroundColor(int color) {
this.backgroundColor = color;
}
@Override
public int getOutlineGradientTopColor() {
return outlineGradientTopColor;
}
@Override
public void setOutlineGradientTopColor(int color) {
this.outlineGradientTopColor = color;
}
@Override
public int getOutlineGradientBottomColor() {
return outlineGradientBottomColor;
}
@Override
public void setOutlineGradientBottomColor(int color) {
this.outlineGradientBottomColor = color;
}
}

View File

@@ -1,28 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.mixin.inject;
import dev.architectury.extensions.injected.InjectedFoodPropertiesBuilderExtension;
import net.minecraft.world.food.FoodProperties;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(FoodProperties.Builder.class)
public class MixinFoodPropertiesBuilder implements InjectedFoodPropertiesBuilderExtension {
}

View File

@@ -37,6 +37,7 @@ import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import java.util.UUID;
@@ -74,7 +75,7 @@ public class SpawnEntityPacket {
if (Minecraft.getInstance().level == null) {
throw new IllegalStateException("Client world is null!");
}
var entity = payload.entityType().create(Minecraft.getInstance().level);
var entity = payload.entityType().create(Minecraft.getInstance().level, EntitySpawnReason.LOAD);
if (entity == null) {
throw new IllegalStateException("Created entity is null!");
}

View File

@@ -19,9 +19,7 @@
package dev.architectury.registry.fuel;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
public final class FuelRegistry {
private FuelRegistry() {
@@ -34,10 +32,10 @@ public final class FuelRegistry {
* and {@code -1} to use vanilla logic
* @param items the array of items to register for
*/
@ExpectPlatform
/*@ExpectPlatform
public static void register(int time, ItemLike... items) {
throw new AssertionError();
}
}*/
/**
* Returns the burn time of an {@link ItemStack}.
@@ -45,8 +43,8 @@ public final class FuelRegistry {
* @param stack the stack
* @return the burn time of the stack, returns {@code 0} if not a fuel
*/
@ExpectPlatform
/*@ExpectPlatform
public static int get(ItemStack stack) {
throw new AssertionError();
}
}*/
}

View File

@@ -84,7 +84,7 @@ public final class RegistrarManager {
public static <T> ResourceLocation getId(T object, @Nullable ResourceKey<Registry<T>> fallback) {
if (fallback == null)
return null;
return getId(object, (Registry<T>) BuiltInRegistries.REGISTRY.get(fallback.location()));
return getId(object, (Registry<T>) BuiltInRegistries.REGISTRY.getValue(fallback.location()));
}
/**

View File

@@ -10,7 +10,6 @@
"inject.MixinBucketItem",
"inject.MixinEntityType",
"inject.MixinFluid",
"inject.MixinFoodPropertiesBuilder",
"inject.MixinItem",
"inject.MixinItemProperties",
"inject.MixinLiquidBlock",

View File

@@ -113,10 +113,6 @@ accessible field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map
mutable field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map;
accessible field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map;
mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map;
transitive-accessible field net/minecraft/world/level/Explosion source Lnet/minecraft/world/entity/Entity;
transitive-mutable field net/minecraft/world/level/Explosion source Lnet/minecraft/world/entity/Entity;
transitive-accessible field net/minecraft/world/level/Explosion radius F
transitive-mutable field net/minecraft/world/level/Explosion radius F
transitive-accessible method net/minecraft/world/entity/player/Player closeContainer ()V
transitive-accessible method net/minecraft/client/renderer/RenderType create (Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;ILnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType;
transitive-accessible method net/minecraft/client/renderer/RenderType create (Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;Lcom/mojang/blaze3d/vertex/VertexFormat$Mode;IZZLnet/minecraft/client/renderer/RenderType$CompositeState;)Lnet/minecraft/client/renderer/RenderType$CompositeRenderType;
@@ -139,7 +135,7 @@ accessible field net/minecraft/client/multiplayer/MultiPlayerGameMode connection
##############################
# Constructors of non-abstract item classes
transitive-accessible method net/minecraft/world/item/DiggerItem <init> (Lnet/minecraft/world/item/Tier;Lnet/minecraft/tags/TagKey;Lnet/minecraft/world/item/Item$Properties;)V
transitive-accessible method net/minecraft/world/item/DiggerItem <init> (Lnet/minecraft/world/item/ToolMaterial;Lnet/minecraft/tags/TagKey;FFLnet/minecraft/world/item/Item$Properties;)V
# Constructors of non-abstract block classes
transitive-accessible method net/minecraft/world/level/block/AttachedStemBlock <init> (Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
@@ -157,13 +153,14 @@ transitive-accessible method net/minecraft/world/level/block/CakeBlock <init> (L
transitive-accessible method net/minecraft/world/level/block/CandleCakeBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CartographyTableBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CarvedPumpkinBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/ChestBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;Ljava/util/function/Supplier;)V
transitive-accessible method net/minecraft/world/level/block/ChestBlock <init> (Ljava/util/function/Supplier;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/ChorusFlowerBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/ChorusPlantBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CoralFanBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CoralPlantBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CoralWallFanBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CraftingTableBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CreakingHeartBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CropBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/DeadBushBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/DecoratedPotBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
@@ -175,7 +172,6 @@ transitive-accessible method net/minecraft/world/level/block/EndGatewayBlock <in
transitive-accessible method net/minecraft/world/level/block/EndPortalBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/EndRodBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/EnderChestBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/EquipableCarvedPumpkinBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FarmBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FletchingTableBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FungusBlock <init> (Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
@@ -248,12 +244,17 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard LIGHT
transitive-accessible field net/minecraft/client/renderer/RenderStateShard GLINT_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard CRUMBLING_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard TRANSLUCENT_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard VIGNETTE_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard CROSSHAIR_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard MOJANG_LOGO_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NAUSEA_OVERLAY_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_LIGHTMAP_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_TEX_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_TEX_LIGHTMAP_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_TEXTURE_COLOR_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_SOLID_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_CUTOUT_MIPPED_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_CUTOUT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
@@ -265,7 +266,6 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDE
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_CUTOUT_NO_CULL_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_CUTOUT_NO_CULL_Z_OFFSET_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ITEM_ENTITY_TRANSLUCENT_CULL_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_TRANSLUCENT_CULL_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_TRANSLUCENT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_TRANSLUCENT_EMISSIVE_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_SMOOTH_CUTOUT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
@@ -283,7 +283,6 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDE
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GLINT_TRANSLUCENT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GLINT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_GLINT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_GLINT_DIRECT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_CRUMBLING_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_TEXT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_TEXT_BACKGROUND_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
@@ -324,6 +323,7 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard DEPTH
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_LAYERING Lnet/minecraft/client/renderer/RenderStateShard$LayeringStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POLYGON_OFFSET_LAYERING Lnet/minecraft/client/renderer/RenderStateShard$LayeringStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard VIEW_OFFSET_Z_LAYERING Lnet/minecraft/client/renderer/RenderStateShard$LayeringStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard VIEW_OFFSET_Z_LAYERING_FORWARD Lnet/minecraft/client/renderer/RenderStateShard$LayeringStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard MAIN_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard OUTLINE_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard TRANSLUCENT_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;

View File

@@ -19,9 +19,6 @@
"net/minecraft/class_1755": [
"dev/architectury/extensions/injected/InjectedBucketItemExtension"
],
"net/minecraft/class_4174$class_4175": [
"dev/architectury/extensions/injected/InjectedFoodPropertiesBuilderExtension"
],
"net/minecraft/class_2404": [
"dev/architectury/extensions/injected/InjectedLiquidBlockExtension"
]

View File

@@ -128,7 +128,7 @@ unifiedPublishing {
curseforge {
token = CURSE_API_KEY
id = rootProject.curseforge_id
gameVersions.addAll "Java 21", project.minecraft_version
gameVersions.addAll "Java 21", "1.21.2-Snapshot"//, project.minecraft_version
}
}

View File

@@ -78,9 +78,9 @@ public class EventHandlerImpl {
CommandRegistrationCallback.EVENT.register((dispatcher, registry, selection) -> CommandRegistrationEvent.EVENT.invoker().register(dispatcher, registry, selection));
UseItemCallback.EVENT.register((player, world, hand) -> InteractionEvent.RIGHT_CLICK_ITEM.invoker().click(player, hand).asMinecraft());
UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> InteractionEvent.RIGHT_CLICK_BLOCK.invoker().click(player, hand, hitResult.getBlockPos(), hitResult.getDirection()).asMinecraft());
AttackBlockCallback.EVENT.register((player, world, hand, pos, face) -> InteractionEvent.LEFT_CLICK_BLOCK.invoker().click(player, hand, pos, face).asMinecraft());
UseItemCallback.EVENT.register((player, world, hand) -> InteractionEvent.RIGHT_CLICK_ITEM.invoker().click(player, hand));
UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> InteractionEvent.RIGHT_CLICK_BLOCK.invoker().click(player, hand, hitResult.getBlockPos(), hitResult.getDirection()));
AttackBlockCallback.EVENT.register((player, world, hand, pos, face) -> InteractionEvent.LEFT_CLICK_BLOCK.invoker().click(player, hand, pos, face));
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> PlayerEvent.ATTACK_ENTITY.invoker().attack(player, world, entity, hand, hitResult).asMinecraft());
LootTableEvents.MODIFY.register((key, tableBuilder, source) -> LootEvent.MODIFY_LOOT_TABLE.invoker().modifyLootTable(key, new LootTableModificationContextImpl(tableBuilder), source.isBuiltin()));

View File

@@ -19,18 +19,15 @@
package dev.architectury.hooks.item.fabric;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
public class ItemStackHooksImpl {
public static boolean hasCraftingRemainingItem(ItemStack stack) {
return stack.getItem().hasCraftingRemainingItem();
return !getCraftingRemainingItem(stack).isEmpty();
}
public static ItemStack getCraftingRemainingItem(ItemStack stack) {
if (!hasCraftingRemainingItem(stack)) return ItemStack.EMPTY;
Item item = stack.getItem().getCraftingRemainingItem();
return item == null || item == Items.AIR ? ItemStack.EMPTY : item.getDefaultInstance();
ItemStack remainder = stack.getItem().getRecipeRemainder(stack);
return remainder == null || remainder.isEmpty() ? ItemStack.EMPTY : remainder;
}
}

View File

@@ -1,33 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.hooks.item.food.fabric;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.food.FoodProperties;
import java.util.function.Supplier;
public class FoodPropertiesHooksImpl {
public static void effect(FoodProperties.Builder builder,
Supplier<? extends MobEffectInstance> effectSupplier, float chance) {
// Fabric doesn't have deferred registration, so the mob effect should always be available anyway
builder.effect(effectSupplier.get(), chance);
}
}

View File

@@ -20,8 +20,8 @@
package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.EntityEvent;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.BaseSpawner;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
@@ -35,17 +35,17 @@ public abstract class MixinBaseSpawner {
method = "serverTick",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/Mob;checkSpawnRules(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/world/entity/MobSpawnType;)Z",
target = "Lnet/minecraft/world/entity/Mob;checkSpawnRules(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/world/entity/EntitySpawnReason;)Z",
ordinal = 0
)
)
private boolean checkSpawnerSpawn(Mob mob, LevelAccessor level, MobSpawnType type) {
private boolean checkSpawnerSpawn(Mob mob, LevelAccessor level, EntitySpawnReason reason) {
var result = EntityEvent.LIVING_CHECK_SPAWN.invoker()
.canSpawn(mob, level, mob.getX(), mob.getY(), mob.getZ(), type, (BaseSpawner) (Object) this);
.canSpawn(mob, level, mob.getX(), mob.getY(), mob.getZ(), reason, (BaseSpawner) (Object) this);
if (result.value() != null) {
return result.value();
}
return mob.checkSpawnRules(level, type) && mob.checkSpawnObstruction(level);
return mob.checkSpawnRules(level, reason) && mob.checkSpawnObstruction(level);
}
@Redirect(

View File

@@ -21,7 +21,7 @@ package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.PlayerEvent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.ItemStack;
@@ -46,10 +46,10 @@ public class MixinBucketItem {
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true
)
public void fillBucket(Level level, Player player, InteractionHand hand, CallbackInfoReturnable<InteractionResultHolder<ItemStack>> cir, ItemStack stack, BlockHitResult target) {
public void fillBucket(Level level, Player player, InteractionHand hand, CallbackInfoReturnable<InteractionResult> cir, ItemStack stack, BlockHitResult target) {
var result = PlayerEvent.FILL_BUCKET.invoker().fill(player, level, stack, target);
if (result.interruptsFurtherEvaluation() && result.value() != null) {
cir.setReturnValue(result.asMinecraft());
if (result != InteractionResult.PASS) {
cir.setReturnValue(result);
cir.cancel();
}
}

View File

@@ -19,17 +19,17 @@
package dev.architectury.mixin.fabric;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.EntityEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.npc.CatSpawner;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(CatSpawner.class)
public abstract class MixinCatSpawner {
@@ -37,14 +37,15 @@ public abstract class MixinCatSpawner {
method = "spawnCat",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/animal/Cat;finalizeSpawn(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/MobSpawnType;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;",
ordinal = 0
target = "Lnet/minecraft/world/entity/EntityType;create(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/EntitySpawnReason;)Lnet/minecraft/world/entity/Entity;",
ordinal = 0,
shift = At.Shift.BY,
by = 3
),
cancellable = true,
locals = LocalCapture.CAPTURE_FAILHARD
cancellable = true
)
private void checkCatSpawn(BlockPos pos, ServerLevel level, CallbackInfoReturnable<Integer> cir, Cat entity) {
if (EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, pos.getX(), pos.getY(), pos.getZ(), MobSpawnType.NATURAL, null).value() == Boolean.FALSE) {
private void checkCatSpawn(BlockPos pos, ServerLevel level, CallbackInfoReturnable<Integer> cir, @Local Cat entity) {
if (EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, pos.getX(), pos.getY(), pos.getZ(), EntitySpawnReason.NATURAL, null).value() == Boolean.FALSE) {
cir.setReturnValue(0);
cir.cancel();
}

View File

@@ -20,12 +20,9 @@
package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.ChunkEvent;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.status.ChunkStatus;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -42,10 +39,10 @@ public class MixinChunkMap {
@Inject(
method = "save",
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;write(Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/nbt/CompoundTag;)Ljava/util/concurrent/CompletableFuture;", ordinal = 0),
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;write(Lnet/minecraft/world/level/ChunkPos;Ljava/util/function/Supplier;)Ljava/util/concurrent/CompletableFuture;", ordinal = 0),
locals = LocalCapture.CAPTURE_FAILHARD
)
private void save(ChunkAccess chunkAccess, CallbackInfoReturnable<Boolean> cir, ChunkPos pos, ChunkStatus chunkStatus, CompoundTag nbt) {
ChunkEvent.SAVE_DATA.invoker().save(chunkAccess, this.level, nbt);
private void save(ChunkAccess chunkAccess, CallbackInfoReturnable<Boolean> cir) {
ChunkEvent.SAVE_DATA.invoker().save(chunkAccess, this.level);
}
}

View File

@@ -1,55 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.mixin.fabric;
import com.mojang.serialization.Codec;
import dev.architectury.event.events.common.ChunkEvent;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.ai.village.poi.PoiManager;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.chunk.status.ChunkType;
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import net.minecraft.world.level.levelgen.blending.BlendingData;
import net.minecraft.world.level.lighting.LevelLightEngine;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(ChunkSerializer.class)
public class MixinChunkSerializer {
@Inject(method = "read", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void load(ServerLevel serverLevel, PoiManager poiManager, RegionStorageInfo regionStorageInfo, ChunkPos chunkPos, CompoundTag compoundTag,
CallbackInfoReturnable<ProtoChunk> cir, ChunkPos chunkPos2, UpgradeData upgradeData,
boolean bl, ListTag listTag, int i, LevelChunkSection[] levelChunkSections, boolean bl2,
ChunkSource chunkSource, LevelLightEngine levelLightEngine, Registry<Biome> registry,
Codec<PalettedContainer<Holder<Biome>>> codec, boolean bl3, long m,
ChunkType chunkType, BlendingData blendingData, ChunkAccess chunkAccess) {
ChunkEvent.LOAD_DATA.invoker().load(chunkAccess, serverLevel, compoundTag);
}
}

View File

@@ -19,15 +19,29 @@
package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.EntityEvent;
import dev.architectury.hooks.level.entity.fabric.EntityHooksImpl;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.entity.EntityInLevelCallback;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(Entity.class)
public class MixinEntity {
@Inject(method = "hurtClient", at = @At("HEAD"), cancellable = true)
private void hurtClient(DamageSource damageSource, CallbackInfoReturnable<Boolean> cir) {
if ((Object) this instanceof Player) return;
if (EntityEvent.LIVING_HURT.invoker().hurt((LivingEntity) (Object) this, damageSource, 0).isFalse()) {
cir.setReturnValue(false);
}
}
@ModifyVariable(method = "setLevelCallback", argsOnly = true, ordinal = 0, at = @At("HEAD"))
public EntityInLevelCallback modifyLevelCallback_setLevelCallback(EntityInLevelCallback callback) {
return EntityHooksImpl.wrapEntityInLevelCallback((Entity) (Object) this, callback);

View File

@@ -19,20 +19,19 @@
package dev.architectury.mixin.fabric;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.BlockEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.FallingBlockEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(FallingBlockEntity.class)
public abstract class MixinFallingBlockEntity extends Entity {
@@ -44,9 +43,8 @@ public abstract class MixinFallingBlockEntity extends Entity {
private BlockState blockState;
@Inject(method = "tick", at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/level/block/Fallable;onLand(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/item/FallingBlockEntity;)V"),
locals = LocalCapture.CAPTURE_FAILHARD)
public void handleLand(CallbackInfo ci, Block block, BlockPos blockPos2, boolean bl, boolean bl2, double d, BlockState blockState) {
BlockEvent.FALLING_LAND.invoker().onLand(this.level(), blockPos2, this.blockState, blockState, (FallingBlockEntity) (Object) this);
target = "Lnet/minecraft/world/level/block/Fallable;onLand(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/item/FallingBlockEntity;)V"))
public void handleLand(CallbackInfo ci, @Local BlockPos blockPos, @Local BlockState blockState) {
BlockEvent.FALLING_LAND.invoker().onLand(this.level(), blockPos, this.blockState, blockState, (FallingBlockEntity) (Object) this);
}
}

View File

@@ -21,6 +21,7 @@ package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.InteractionEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.FarmBlock;
@@ -54,7 +55,7 @@ public abstract class MixinFarmBlock {
var triple = turnToDirtLocal.get();
turnToDirtLocal.remove();
if (triple != null && triple.getLeft() == pos.asLong() && triple.getRight() == entity) {
if (InteractionEvent.FARMLAND_TRAMPLE.invoker().trample(level, pos, state, triple.getMiddle(), entity).value() != null) {
if (InteractionEvent.FARMLAND_TRAMPLE.invoker().trample(level, pos, state, triple.getMiddle(), entity) != InteractionResult.PASS) {
ci.cancel();
}
}

View File

@@ -1,46 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.ExplosionEvent;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(Level.class)
public class MixinLevel {
@Inject(method = "explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;ZLnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)Lnet/minecraft/world/level/Explosion;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Explosion;explode()V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void explodePre(Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionDamageCalculator, double d, double e, double f, float g, boolean bl, Level.ExplosionInteraction explosionInteraction, boolean bl2, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder<SoundEvent> soundEvent, CallbackInfoReturnable<Explosion> cir, Explosion.BlockInteraction blockInteraction, Explosion explosion) {
if (ExplosionEvent.PRE.invoker().explode((Level) (Object) this, explosion).isFalse()) {
cir.setReturnValue(explosion);
}
}
}

View File

@@ -21,6 +21,7 @@ package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.EntityEvent;
import dev.architectury.extensions.ItemExtension;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
@@ -33,8 +34,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntity.class)
public class MixinLivingEntity {
@Inject(method = "hurt", at = @At("HEAD"), cancellable = true)
private void hurt(DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
@Inject(method = "hurtServer", at = @At("HEAD"), cancellable = true)
private void hurtServer(ServerLevel level, DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
if ((Object) this instanceof Player) return;
if (EntityEvent.LIVING_HURT.invoker().hurt((LivingEntity) (Object) this, damageSource, f).isFalse()) {
cir.setReturnValue(false);

View File

@@ -21,8 +21,8 @@ package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.EntityEvent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.NaturalSpawner;
import org.spongepowered.asm.mixin.Mixin;
@@ -46,7 +46,7 @@ public abstract class MixinNaturalSpawner {
)
)
private static boolean overrideNaturalSpawnCondition(ServerLevel level, Mob entity, double f) {
var result = EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, entity.xOld, entity.yOld, entity.zOld, MobSpawnType.NATURAL, null);
var result = EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, entity.xOld, entity.yOld, entity.zOld, EntitySpawnReason.NATURAL, null);
if (result.value() != null) {
return result.value();
} else {
@@ -58,16 +58,16 @@ public abstract class MixinNaturalSpawner {
method = "spawnMobsForChunkGeneration",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/Mob;checkSpawnRules(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/world/entity/MobSpawnType;)Z",
target = "Lnet/minecraft/world/entity/Mob;checkSpawnRules(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/world/entity/EntitySpawnReason;)Z",
ordinal = 0
)
)
private static boolean overrideChunkGenSpawnCondition(Mob mob, LevelAccessor level, MobSpawnType type) {
var result = EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(mob, level, mob.xOld, mob.yOld, mob.zOld, MobSpawnType.CHUNK_GENERATION, null);
private static boolean overrideChunkGenSpawnCondition(Mob mob, LevelAccessor level, EntitySpawnReason reason) {
var result = EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(mob, level, mob.xOld, mob.yOld, mob.zOld, reason, null);
if (result.value() != null) {
return result.value();
} else {
return mob.checkSpawnRules(level, type);
return mob.checkSpawnRules(level, reason);
}
}

View File

@@ -19,21 +19,18 @@
package dev.architectury.mixin.fabric;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.EntityEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.monster.PatrollingMonster;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.PatrolSpawner;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.Random;
@Mixin(PatrolSpawner.class)
public abstract class MixinPatrolSpawner {
@@ -42,16 +39,15 @@ public abstract class MixinPatrolSpawner {
method = "spawnPatrolMember",
at = @At(
value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/world/entity/EntityType;create(Lnet/minecraft/world/level/Level;)Lnet/minecraft/world/entity/Entity;",
target = "Lnet/minecraft/world/entity/EntityType;create(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/EntitySpawnReason;)Lnet/minecraft/world/entity/Entity;",
ordinal = 0,
shift = At.Shift.BY,
by = 2
),
cancellable = true,
locals = LocalCapture.CAPTURE_FAILHARD
cancellable = true
)
private void checkPatrolSpawn(ServerLevel level, BlockPos pos, RandomSource r, boolean b, CallbackInfoReturnable<Boolean> cir, BlockState blockState, PatrollingMonster entity) {
var result = EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, pos.getX(), pos.getY(), pos.getZ(), MobSpawnType.PATROL, null);
private void checkPatrolSpawn(ServerLevel level, BlockPos pos, RandomSource r, boolean b, CallbackInfoReturnable<Boolean> cir, @Local PatrollingMonster entity) {
var result = EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, pos.getX(), pos.getY(), pos.getZ(), EntitySpawnReason.PATROL, null);
if (result.value() != null) {
cir.setReturnValue(result.value());
}

View File

@@ -19,26 +19,17 @@
package dev.architectury.mixin.fabric;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.EntityEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.stats.ServerStatsCounter;
import net.minecraft.util.RandomSource;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.monster.Phantom;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.PhantomSpawner;
import net.minecraft.world.level.material.FluidState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.Iterator;
@Mixin(PhantomSpawner.class)
public abstract class MixinPhantomSpawner {
@@ -47,18 +38,15 @@ public abstract class MixinPhantomSpawner {
method = "tick",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/monster/Phantom;finalizeSpawn(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/world/DifficultyInstance;Lnet/minecraft/world/entity/MobSpawnType;Lnet/minecraft/world/entity/SpawnGroupData;)Lnet/minecraft/world/entity/SpawnGroupData;",
target = "Lnet/minecraft/world/entity/EntityType;create(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/EntitySpawnReason;)Lnet/minecraft/world/entity/Entity;",
ordinal = 0,
shift = At.Shift.BEFORE
shift = At.Shift.BY,
by = 3
),
cancellable = true,
locals = LocalCapture.CAPTURE_FAILSOFT // SOFT, because this will break in 2 seconds
cancellable = true
)
private void checkPhantomSpawn(ServerLevel level, boolean bl, boolean bl2, CallbackInfoReturnable<Integer> cir,
RandomSource random, int i, Iterator<ServerPlayer> it, ServerPlayer player, BlockPos pos, DifficultyInstance diff,
ServerStatsCounter serverStatsCounter, int j, int k, BlockPos pos2,
BlockState blockState, FluidState fluidState, SpawnGroupData sgd, int l, int m, Phantom entity) {
if (EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, pos.getX(), pos.getY(), pos.getZ(), MobSpawnType.NATURAL, null).value() == Boolean.FALSE) {
private void checkPhantomSpawn(ServerLevel level, boolean bl, boolean bl2, CallbackInfoReturnable<Integer> cir, @Local(ordinal = 1) BlockPos pos, @Local Phantom entity) {
if (EntityEvent.LIVING_CHECK_SPAWN.invoker().canSpawn(entity, level, pos.getX(), pos.getY(), pos.getZ(), EntitySpawnReason.NATURAL, null).value() == Boolean.FALSE) {
cir.setReturnValue(0);
cir.cancel();
}

View File

@@ -0,0 +1,45 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.mixin.fabric;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.ChunkEvent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.ai.village.poi.PoiManager;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ProtoChunk;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import net.minecraft.world.level.chunk.storage.SerializableChunkData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(SerializableChunkData.class)
public class MixinSerializableChunkData {
@Inject(method = "read", at = @At("RETURN"))
private void load(ServerLevel serverLevel, PoiManager poiManager, RegionStorageInfo regionStorageInfo, ChunkPos chunkPos,
CallbackInfoReturnable<ProtoChunk> cir,
@Local ChunkAccess chunkAccess) {
// TODO: Get the CompoundTag from constructor somewhere
ChunkEvent.LOAD_DATA.invoker().load(chunkAccess, serverLevel);
}
}

View File

@@ -19,32 +19,27 @@
package dev.architectury.mixin.fabric;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.ExplosionEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.world.level.ServerExplosion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.List;
import java.util.Set;
@Mixin(Explosion.class)
public class MixinExplosion {
@Mixin(ServerExplosion.class)
public abstract class MixinServerExplosion {
@Shadow
@Final
private Level level;
public abstract ServerLevel level();
@SuppressWarnings("InvalidInjectorMethodSignature")
@Inject(method = "explode", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;<init>(DDD)V", ordinal = 1),
locals = LocalCapture.CAPTURE_FAILHARD)
private void explodePost(CallbackInfo ci, Set<BlockPos> set, int i, float q, int r, int s, int t, int u, int v, int w, List<Entity> list) {
ExplosionEvent.DETONATE.invoker().explode(level, (Explosion) (Object) this, list);
@Inject(method = "hurtEntities", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;", ordinal = 0))
private void explodePost(CallbackInfo ci, @Local List<Entity> list) {
ExplosionEvent.DETONATE.invoker().explode(level(), (ServerExplosion) (Object) this, list);
}
}

View File

@@ -19,11 +19,21 @@
package dev.architectury.mixin.fabric;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.common.ExplosionEvent;
import dev.architectury.event.events.common.LifecycleEvent;
import dev.architectury.hooks.fabric.PersistentEntitySectionManagerHooks;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.ProgressListener;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerExplosion;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -50,4 +60,12 @@ public class MixinServerLevel {
private void addEntity(Entity entity, CallbackInfoReturnable<Boolean> cir) {
((PersistentEntitySectionManagerHooks) this.entityManager).architectury_attachLevel((ServerLevel) (Object) this);
}
@Inject(method = "explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/particles/ParticleOptions;Lnet/minecraft/core/Holder;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/ServerExplosion;explode()V"), cancellable = true)
private void explodePre(Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionDamageCalculator, double d, double e, double f, float g, boolean bl, Level.ExplosionInteraction explosionInteraction, ParticleOptions particleOptions, ParticleOptions particleOptions2, Holder<SoundEvent> soundEvent, CallbackInfo ci, @Local Explosion.BlockInteraction blockInteraction, @Local ServerExplosion explosion) {
if (ExplosionEvent.PRE.invoker().explode((Level) (Object) this, explosion).isFalse()) {
ci.cancel();
}
}
}

View File

@@ -20,6 +20,7 @@
package dev.architectury.mixin.fabric;
import dev.architectury.event.events.common.EntityEvent;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
@@ -30,8 +31,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = {Player.class})
public class PlayerAttackInvoker {
@Inject(method = "hurt", at = @At("HEAD"), cancellable = true)
private void hurt(DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
@Inject(method = "hurtServer", at = @At("HEAD"), cancellable = true)
private void hurtServer(ServerLevel level, DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
if (EntityEvent.LIVING_HURT.invoker().hurt((LivingEntity) (Object) this, damageSource, f).isFalse() && (Object) this instanceof Player) {
cir.setReturnValue(false);
}

View File

@@ -20,7 +20,6 @@
package dev.architectury.mixin.fabric.client;
import dev.architectury.event.events.common.EntityEvent;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.player.RemotePlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
@@ -30,11 +29,11 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = {LocalPlayer.class, RemotePlayer.class})
@Mixin(value = {RemotePlayer.class})
public class ClientPlayerAttackInvoker {
@Inject(method = "hurt", at = @At("HEAD"), cancellable = true)
private void hurt(DamageSource damageSource, float f, CallbackInfoReturnable<Boolean> cir) {
if (EntityEvent.LIVING_HURT.invoker().hurt((LivingEntity) (Object) this, damageSource, f).isFalse() && (Object) this instanceof Player) {
@Inject(method = "hurtClient", at = @At("HEAD"), cancellable = true)
private void hurt(DamageSource damageSource, CallbackInfoReturnable<Boolean> cir) {
if (EntityEvent.LIVING_HURT.invoker().hurt((LivingEntity) (Object) this, damageSource, 0).isFalse() && (Object) this instanceof Player) {
cir.setReturnValue(false);
}
}

View File

@@ -26,21 +26,19 @@ import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.function.Supplier;
import java.util.logging.Level;
@Mixin(ClientLevel.class)
public class MixinClientLevel {
@Inject(method = "<init>", at = @At("RETURN"))
private void construct(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey<Level> resourceKey, Holder<DimensionType> holder, int i, int j, Supplier<ProfilerFiller> supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) {
private void construct(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey<Level> resourceKey, Holder<DimensionType> holder, int i, int j, LevelRenderer levelRenderer, boolean bl, long l, int k, CallbackInfo ci) {
ClientLifecycleEvent.CLIENT_LEVEL_LOAD.invoker().act((ClientLevel) (Object) this);
}

View File

@@ -30,11 +30,8 @@ import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.multiplayer.CommonListenerCookie;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
import net.minecraft.network.protocol.game.ClientboundRespawnPacket;
import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket;
import net.minecraft.world.item.crafting.RecipeManager;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.network.protocol.game.*;
import net.minecraft.world.item.crafting.RecipeAccess;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@@ -44,11 +41,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientPacketListener.class)
public abstract class MixinClientPacketListener extends ClientCommonPacketListenerImpl {
@Shadow
@Final
private RecipeManager recipeManager;
@Shadow
private ClientLevel level;
@Shadow
public abstract RecipeAccess recipes();
@Unique
private LocalPlayer tmpPlayer;
@@ -75,7 +73,17 @@ public abstract class MixinClientPacketListener extends ClientCommonPacketListen
@Inject(method = "handleUpdateRecipes", at = @At("RETURN"))
private void handleUpdateRecipes(ClientboundUpdateRecipesPacket clientboundUpdateRecipesPacket, CallbackInfo ci) {
ClientRecipeUpdateEvent.EVENT.invoker().update(recipeManager);
ClientRecipeUpdateEvent.EVENT.invoker().update(recipes());
}
@Inject(method = "handleRecipeBookAdd", at = @At("RETURN"))
private void handleRecipeBookAdd(ClientboundRecipeBookAddPacket packet, CallbackInfo ci) {
ClientRecipeUpdateEvent.ADD.invoker().add(recipes(), packet.entries());
}
@Inject(method = "handleRecipeBookRemove", at = @At("RETURN"))
private void handleRecipeBookRemove(ClientboundRecipeBookRemovePacket packet, CallbackInfo ci) {
ClientRecipeUpdateEvent.REMOVE.invoker().remove(recipes(), packet.recipes());
}
@Inject(method = "sendChat(Ljava/lang/String;)V", at = @At(value = "HEAD"), cancellable = true)

View File

@@ -1,57 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.mixin.fabric.client;
import com.mojang.blaze3d.shaders.Program;
import net.minecraft.client.renderer.EffectInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceProvider;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Unique
@Mixin(value = EffectInstance.class, priority = 950)
public class MixinEffectInstance {
@Redirect(
method = "<init>",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/resources/ResourceLocation;withDefaultNamespace(Ljava/lang/String;)Lnet/minecraft/resources/ResourceLocation;",
ordinal = 0)
)
private ResourceLocation mojangPls(String _0, ResourceProvider rm, String str) {
return mojangPls(ResourceLocation.parse(str), ".json");
}
@Redirect(
method = "getOrCreate",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/resources/ResourceLocation;withDefaultNamespace(Ljava/lang/String;)Lnet/minecraft/resources/ResourceLocation;",
ordinal = 0)
)
private static ResourceLocation mojangPls(String _0, ResourceProvider rm, Program.Type type, String str) {
return mojangPls(ResourceLocation.parse(str), type.getExtension());
}
private static ResourceLocation mojangPls(ResourceLocation rl, String ext) {
return ResourceLocation.fromNamespaceAndPath(rl.getNamespace(), "shaders/program/" + rl.getPath() + ext);
}
}

View File

@@ -19,29 +19,18 @@
package dev.architectury.mixin.fabric.client;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.shaders.Program;
import com.mojang.datafixers.util.Pair;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.events.client.ClientGuiEvent;
import dev.architectury.event.events.client.ClientReloadShadersEvent;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.server.packs.resources.ResourceProvider;
import org.joml.Matrix4f;
import org.joml.Matrix4fStack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.List;
import java.util.function.Consumer;
@Mixin(value = GameRenderer.class, priority = 1100)
public abstract class MixinGameRenderer {
@@ -54,8 +43,8 @@ public abstract class MixinGameRenderer {
@Inject(method = "render(Lnet/minecraft/client/DeltaTracker;Z)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;renderWithTooltip(Lnet/minecraft/client/gui/GuiGraphics;IIF)V",
ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
public void renderScreenPre(DeltaTracker tickDelta, boolean tick, CallbackInfo ci, boolean isGameLoadFinished, int mouseX, int mouseY, Window window, Matrix4f matrix, Matrix4fStack matrices, GuiGraphics graphics) {
ordinal = 0), cancellable = true)
public void renderScreenPre(DeltaTracker tickDelta, boolean tick, CallbackInfo ci, @Local(ordinal = 0) int mouseX, @Local(ordinal = 1) int mouseY, @Local GuiGraphics graphics) {
if (ClientGuiEvent.RENDER_PRE.invoker().render(minecraft.screen, graphics, mouseX, mouseY, tickDelta).isFalse()) {
ci.cancel();
}
@@ -63,16 +52,8 @@ public abstract class MixinGameRenderer {
@Inject(method = "render(Lnet/minecraft/client/DeltaTracker;Z)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;renderWithTooltip(Lnet/minecraft/client/gui/GuiGraphics;IIF)V",
shift = At.Shift.AFTER, ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void renderScreenPost(DeltaTracker tickDelta, boolean tick, CallbackInfo ci, boolean isGameLoadFinished, int mouseX, int mouseY, Window window, Matrix4f matrix, Matrix4fStack matrices, GuiGraphics graphics) {
shift = At.Shift.AFTER, ordinal = 0))
public void renderScreenPost(DeltaTracker tickDelta, boolean tick, CallbackInfo ci, @Local(ordinal = 0) int mouseX, @Local(ordinal = 1) int mouseY, @Local GuiGraphics graphics) {
ClientGuiEvent.RENDER_POST.invoker().render(minecraft.screen, graphics, mouseX, mouseY, tickDelta);
}
@Inject(method = "reloadShaders",
at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void reloadShaders(ResourceProvider provider, CallbackInfo ci, List<Program> programs, List<Pair<ShaderInstance, Consumer<ShaderInstance>>> shaders) {
ClientReloadShadersEvent.EVENT.invoker().reload(provider, (shader, callback) -> {
shaders.add(Pair.of(shader, callback));
});
}
}

View File

@@ -20,13 +20,14 @@
package dev.architectury.mixin.fabric.client;
import dev.architectury.event.events.client.ClientTooltipEvent;
import dev.architectury.impl.TooltipEventColorContextImpl;
import dev.architectury.impl.TooltipEventPositionContextImpl;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
@@ -52,28 +53,25 @@ public abstract class MixinGuiGraphics {
}
@Inject(method = "renderTooltipInternal", at = @At("HEAD"), cancellable = true)
private void renderTooltip(Font font, List<? extends ClientTooltipComponent> list, int x, int y, ClientTooltipPositioner positioner, CallbackInfo ci) {
private void renderTooltip(Font font, List<ClientTooltipComponent> list, int x, int y, ClientTooltipPositioner positioner, @Nullable ResourceLocation background, CallbackInfo ci) {
if (!list.isEmpty()) {
var colorContext = TooltipEventColorContextImpl.CONTEXT.get();
colorContext.reset();
var positionContext = tooltipPositionContext.get();
positionContext.reset(x, y);
if (ClientTooltipEvent.RENDER_PRE.invoker().renderTooltip((GuiGraphics) (Object) this, list, x, y).isFalse()) {
ci.cancel();
} else {
ClientTooltipEvent.RENDER_MODIFY_COLOR.invoker().renderTooltip((GuiGraphics) (Object) this, x, y, colorContext);
ClientTooltipEvent.RENDER_MODIFY_POSITION.invoker().renderTooltip((GuiGraphics) (Object) this, positionContext);
}
}
}
@ModifyVariable(method = "renderTooltipInternal(Lnet/minecraft/client/gui/Font;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V",
@ModifyVariable(method = "renderTooltipInternal",
at = @At(value = "HEAD"), ordinal = 0, argsOnly = true)
private int modifyTooltipX(int original) {
return tooltipPositionContext.get().getTooltipX();
}
@ModifyVariable(method = "renderTooltipInternal(Lnet/minecraft/client/gui/Font;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V",
@ModifyVariable(method = "renderTooltipInternal",
at = @At(value = "HEAD"), ordinal = 1, argsOnly = true)
private int modifyTooltipY(int original) {
return tooltipPositionContext.get().getTooltipY();

View File

@@ -19,6 +19,7 @@
package dev.architectury.mixin.fabric.client;
import com.llamalad7.mixinextras.sugar.Local;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.client.ClientRawInputEvent;
import dev.architectury.event.events.client.ClientScreenInputEvent;
@@ -34,7 +35,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(KeyboardHandler.class)
public class MixinKeyboardHandler {
@@ -42,7 +42,7 @@ public class MixinKeyboardHandler {
@Final
private Minecraft minecraft;
@ModifyVariable(method = {"method_1458", "lambda$charTyped$5"}, at = @At("HEAD"), ordinal = 0, argsOnly = true)
@ModifyVariable(method = {"method_1458", "lambda$charTyped$6"}, at = @At("HEAD"), ordinal = 0, argsOnly = true)
private static GuiEventListener wrapCharTypedFirst(GuiEventListener screen) {
if (screen instanceof ScreenInputDelegate delegate) {
return delegate.architectury_delegateInputs();
@@ -50,7 +50,7 @@ public class MixinKeyboardHandler {
return screen;
}
@ModifyVariable(method = {"method_1473", "lambda$charTyped$6"}, at = @At("HEAD"), ordinal = 0, argsOnly = true)
@ModifyVariable(method = {"method_1473", "lambda$charTyped$7"}, at = @At("HEAD"), ordinal = 0, argsOnly = true)
private static GuiEventListener wrapCharTypedSecond(GuiEventListener screen) {
if (screen instanceof ScreenInputDelegate delegate) {
return delegate.architectury_delegateInputs();
@@ -79,9 +79,9 @@ public class MixinKeyboardHandler {
@Inject(method = "keyPress", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/gui/screens/Screen;wrapScreenError(Ljava/lang/Runnable;Ljava/lang/String;Ljava/lang/String;)V",
ordinal = 0, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD,
ordinal = 0, shift = At.Shift.AFTER),
cancellable = true)
public void onKeyAfter(long long_1, int int_1, int int_2, int int_3, int int_4, CallbackInfo info, boolean f3Pressed, Screen screen, boolean[] bls) {
public void onKeyAfter(long long_1, int int_1, int int_2, int int_3, int int_4, CallbackInfo info, @Local Screen screen, @Local boolean[] bls) {
if (!info.isCancelled() && !bls[0]) {
EventResult result;
if (int_3 != 1 && int_3 != 2) {

View File

@@ -1,44 +0,0 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.mixin.fabric.client;
import dev.architectury.impl.TooltipEventColorContextImpl;
import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
@Mixin(TooltipRenderUtil.class)
public abstract class MixinTooltipRenderUtil {
@ModifyConstant(method = "renderTooltipBackground", constant = @Constant(intValue = 0xf0100010))
private static int modifyTooltipBackgroundColor(int original) {
return TooltipEventColorContextImpl.CONTEXT.get().getBackgroundColor();
}
@ModifyConstant(method = "renderTooltipBackground", constant = @Constant(intValue = 0x505000ff))
private static int modifyTooltipOutlineGradientTopColor(int original) {
return TooltipEventColorContextImpl.CONTEXT.get().getOutlineGradientTopColor();
}
@ModifyConstant(method = "renderTooltipBackground", constant = @Constant(intValue = 0x5028007f))
private static int modifyTooltipOutlineGradientBottomColor(int original) {
return TooltipEventColorContextImpl.CONTEXT.get().getOutlineGradientBottomColor();
}
}

View File

@@ -109,7 +109,7 @@ public class CreativeTabRegistryImpl {
private void resolve() {
if (this.tab == null) {
this.tab = BuiltInRegistries.CREATIVE_MODE_TAB.get(name);
this.tab = BuiltInRegistries.CREATIVE_MODE_TAB.getValue(name);
}
}
};

View File

@@ -59,8 +59,8 @@ public class ReloadListenerRegistryImpl {
}
@Override
public CompletableFuture<Void> reload(PreparationBarrier preparationBarrier, ResourceManager resourceManager, ProfilerFiller profilerFiller, ProfilerFiller profilerFiller2, Executor executor, Executor executor2) {
return listener.reload(preparationBarrier, resourceManager, profilerFiller, profilerFiller2, executor, executor2);
public CompletableFuture<Void> reload(PreparationBarrier preparationBarrier, ResourceManager resourceManager, Executor executor, Executor executor2) {
return listener.reload(preparationBarrier, resourceManager, executor, executor2);
}
});
}

View File

@@ -19,23 +19,23 @@
package dev.architectury.registry.fuel.fabric;
import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
public class FuelRegistryImpl {
public static void register(int time, ItemLike... items) {
for (var item : items) {
/*for (var item : items) {
if (time >= 0) {
FuelRegistry.INSTANCE.add(item, time);
} else {
FuelRegistry.INSTANCE.remove(item);
}
}
}*/
}
public static int get(ItemStack stack) {
var time = FuelRegistry.INSTANCE.get(stack.getItem());
return time == null ? 0 : time;
/*var time = FuelRegistry.INSTANCE.get(stack.getItem());
return time == null ? 0 : time;*/
return 0;
}
}

View File

@@ -154,10 +154,10 @@ public class BiomeModificationsImpl {
}
@Override
public Mutable addCarver(GenerationStep.Carving carving, Holder<ConfiguredWorldCarver<?>> feature) {
public Mutable addCarver(Holder<ConfiguredWorldCarver<?>> feature) {
Either<ResourceKey<ConfiguredWorldCarver<?>>, ConfiguredWorldCarver<?>> unwrap = feature.unwrap();
if (unwrap.left().isPresent()) {
this.context.addCarver(carving, unwrap.left().get());
this.context.addCarver(unwrap.left().get());
} else {
throw new UnsupportedOperationException("Cannot add a carver that is not registered: " + unwrap.right().orElseThrow());
}
@@ -165,8 +165,8 @@ public class BiomeModificationsImpl {
}
@Override
public Mutable addCarver(GenerationStep.Carving carving, ResourceKey<ConfiguredWorldCarver<?>> feature) {
this.context.addCarver(carving, feature);
public Mutable addCarver(ResourceKey<ConfiguredWorldCarver<?>> feature) {
this.context.addCarver(feature);
return this;
}
@@ -177,8 +177,8 @@ public class BiomeModificationsImpl {
}
@Override
public Mutable removeCarver(GenerationStep.Carving carving, ResourceKey<ConfiguredWorldCarver<?>> feature) {
context.removeCarver(carving, feature);
public Mutable removeCarver(ResourceKey<ConfiguredWorldCarver<?>> feature) {
context.removeCarver(feature);
return this;
}
}

View File

@@ -52,7 +52,7 @@ public class RegistrarManagerImpl {
private static void listen(ResourceKey<?> resourceKey, ResourceLocation id, Consumer<?> listener) {
if (LISTENED_REGISTRIES.add(resourceKey)) {
Registry<?> registry = java.util.Objects.requireNonNull(BuiltInRegistries.REGISTRY.get(resourceKey.location()), "Registry " + resourceKey + " not found!");
Registry<?> registry = java.util.Objects.requireNonNull(BuiltInRegistries.REGISTRY.getValue(resourceKey.location()), "Registry " + resourceKey + " not found!");
RegistryEntryAddedCallback.event(registry).register((rawId, entryId, object) -> {
RegistryEntryId<?> registryEntryId = new RegistryEntryId<>(resourceKey, entryId);
for (Consumer<?> consumer : LISTENERS.get(registryEntryId)) {
@@ -78,7 +78,7 @@ public class RegistrarManagerImpl {
@Override
public <T> Registrar<T> get(ResourceKey<Registry<T>> key) {
return new RegistrarImpl<>(modId, (Registry<T>) java.util.Objects.requireNonNull(BuiltInRegistries.REGISTRY.get(key.location()), "Registry " + key + " not found!"));
return new RegistrarImpl<>(modId, (Registry<T>) java.util.Objects.requireNonNull(BuiltInRegistries.REGISTRY.getValue(key.location()), "Registry " + key + " not found!"));
}
@Override
@@ -250,7 +250,7 @@ public class RegistrarManagerImpl {
@Override
public @Nullable T get(ResourceLocation id) {
return delegate.get(id);
return delegate.getValue(id);
}
@Override
@@ -286,7 +286,7 @@ public class RegistrarManagerImpl {
@Override
@Nullable
public Holder<T> getHolder(ResourceKey<T> key) {
return delegate.getHolder(key).orElse(null);
return delegate.get(key).orElse(null);
}
@Override

View File

@@ -11,7 +11,6 @@
"client.MixinClientLevel",
"client.MixinClientPacketListener",
"client.MixinDebugScreenOverlay",
"client.MixinEffectInstance",
"client.MixinFabricClientCommandSource",
"client.MixinGameRenderer",
"client.MixinGuiGraphics",
@@ -20,8 +19,7 @@
"client.MixinMinecraft",
"client.MixinMouseHandler",
"client.MixinMultiPlayerGameMode",
"client.MixinScreen",
"client.MixinTooltipRenderUtil"
"client.MixinScreen"
],
"mixins": [
"BiomeAccessor",
@@ -34,17 +32,14 @@
"MixinBucketItem",
"MixinCatSpawner",
"MixinChunkMap",
"MixinChunkSerializer",
"MixinCommands",
"MixinDedicatedServer",
"MixinEntity",
"MixinExplosion",
"MixinFallingBlockEntity",
"MixinFarmBlock",
"MixinFurnaceResultSlot",
"MixinInventory",
"MixinItemEntity",
"MixinLevel",
"MixinLivingEntity",
"MixinNaturalSpawner",
"MixinOcelot",
@@ -55,6 +50,8 @@
"MixinPlayerAdvancements",
"MixinPlayerList",
"MixinResultSlot",
"MixinSerializableChunkData",
"MixinServerExplosion",
"MixinServerLevel",
"MixinServerPlayer",
"MixinServerPlayerGameMode",

View File

@@ -1,21 +1,21 @@
org.gradle.jvmargs=-Xmx6G
org.gradle.daemon=false
platforms=fabric,neoforge
platforms=fabric
minecraft_version=1.21
supported_version=1.21
minecraft_version=24w40a
supported_version=1.21.2 (24w40a)
artifact_type=release
artifact_type=beta
archives_base_name=architectury
archives_base_name_snapshot=architectury-snapshot
base_version=13.0
base_version=14.0
maven_group=dev.architectury
version_suffix=
fabric_loader_version=0.15.11
fabric_api_version=0.100.0+1.21
fabric_loader_version=0.16.5
fabric_api_version=0.105.2+1.21.2
mod_menu_version=11.0.1
forge_version=51.0.0

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -15,10 +15,10 @@ include("common")
include("fabric")
//include("forge")
//include("minecraftforge")
include("neoforge")
//include("neoforge")
include("testmod-common")
include("testmod-fabric")
//include("testmod-forge")
include("testmod-neoforge")
//include("testmod-neoforge")
rootProject.name = "architectury"

View File

@@ -45,20 +45,12 @@ import dev.architectury.utils.EnvExecutor;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.entity.CowRenderer;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.level.block.Blocks;
import java.util.Collections;
import java.util.List;
public class TestMod {
public static final MessageSink SINK = EnvExecutor.getEnvSpecific(() -> ClientOverlayMessageSink::new, () -> ConsoleMessageSink::new);
public static final String MOD_ID = "architectury_test";
@@ -75,7 +67,7 @@ public class TestMod {
TestLoot.init();
TestWorldGeneration.initialize();
EnvExecutor.runInEnv(Env.CLIENT, () -> TestMod.Client::initializeClient);
CreativeTabRegistry.modifyBuiltin(BuiltInRegistries.CREATIVE_MODE_TAB.get(CreativeModeTabs.BUILDING_BLOCKS), (flags, output, canUseGameMasterBlocks) -> {
CreativeTabRegistry.modifyBuiltin(BuiltInRegistries.CREATIVE_MODE_TAB.getValue(CreativeModeTabs.BUILDING_BLOCKS), (flags, output, canUseGameMasterBlocks) -> {
ItemStack sword = Items.DIAMOND_SWORD.getDefaultInstance();
output.acceptBefore(new ItemStack(Items.OAK_WOOD), sword);
output.acceptAfter(Blocks.STRIPPED_OAK_LOG, Items.BEDROCK);

View File

@@ -20,14 +20,15 @@
package dev.architectury.test.entity;
import com.google.common.base.Suppliers;
import dev.architectury.injectables.targets.ArchitecturyTarget;
import dev.architectury.networking.NetworkManager;
import dev.architectury.test.TestMod;
import io.netty.buffer.Unpooled;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerPlayer;
@@ -39,8 +40,8 @@ import net.minecraft.world.level.Level;
import java.util.function.Supplier;
public class TestEntity extends Cow {
public static final Supplier<EntityType<TestEntity>> TYPE = Suppliers.memoize(() -> EntityType.Builder.of(TestEntity::new, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8).build("test_entity"));
public static final Supplier<EntityType<TestEntity>> TYPE_2 = Suppliers.memoize(() -> EntityType.Builder.of(TestEntity::new, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8).build("test_entity_2"));
public static final Supplier<EntityType<TestEntity>> TYPE = Suppliers.memoize(() -> EntityType.Builder.of(TestEntity::new, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8).build(ResourceKey.create(Registries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "test_entity"))));
public static final Supplier<EntityType<TestEntity>> TYPE_2 = Suppliers.memoize(() -> EntityType.Builder.of(TestEntity::new, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8).build(ResourceKey.create(Registries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, "test_entity_2"))));
public TestEntity(EntityType<? extends Cow> entityType, Level level) {
super(entityType, level);

View File

@@ -24,7 +24,6 @@ import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.client.*;
import dev.architectury.event.events.common.*;
import dev.architectury.hooks.level.ExplosionHooks;
import dev.architectury.platform.Platform;
import dev.architectury.test.TestMod;
import dev.architectury.utils.Env;
@@ -37,6 +36,7 @@ import net.minecraft.core.Position;
import net.minecraft.core.Vec3i;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
@@ -134,19 +134,19 @@ public class DebugEvents {
return EventResult.pass();
}));
ExplosionEvent.DETONATE.register((world, explosion, affectedEntities) -> {
TestMod.SINK.accept(world.dimension().location() + " explodes at " + toShortString(ExplosionHooks.getPosition(explosion)) + logSide(world));
TestMod.SINK.accept(world.dimension().location() + " explodes at " + toShortString(explosion.center()) + logSide(world));
});
InteractionEvent.LEFT_CLICK_BLOCK.register((player, hand, pos, face) -> {
TestMod.SINK.accept(player.getScoreboardName() + " left clicks " + toShortString(pos) + logSide(player.level()));
return EventResult.pass();
return InteractionResult.PASS;
});
InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, face) -> {
TestMod.SINK.accept(player.getScoreboardName() + " right clicks " + toShortString(pos) + logSide(player.level()));
return EventResult.pass();
return InteractionResult.PASS;
});
InteractionEvent.RIGHT_CLICK_ITEM.register((player, hand) -> {
TestMod.SINK.accept(player.getScoreboardName() + " uses " + (hand == InteractionHand.MAIN_HAND ? "main hand" : "off hand") + logSide(player.level()));
return CompoundEventResult.pass();
return InteractionResult.PASS;
});
InteractionEvent.INTERACT_ENTITY.register((player, entity, hand) -> {
TestMod.SINK.accept(player.getScoreboardName() + " interacts with " + entity.getScoreboardName() + " using " + (hand == InteractionHand.MAIN_HAND ? "main hand" : "off hand") + logSide(player.level()));
@@ -154,10 +154,10 @@ public class DebugEvents {
});
InteractionEvent.FARMLAND_TRAMPLE.register((level, pos, state, distance, entity) -> {
if (entity instanceof Player && ((Player) entity).getItemBySlot(EquipmentSlot.FEET).getItem() == Items.DIAMOND_BOOTS) {
return EventResult.interrupt(false);
return InteractionResult.FAIL;
}
TestMod.SINK.accept("%s trampled farmland (%s) at %s in %s (Fall height: %f blocks)", entity, state, pos, level, distance);
return EventResult.pass();
return InteractionResult.PASS;
});
LifecycleEvent.SERVER_BEFORE_START.register(instance -> {
TestMod.SINK.accept("Server ready to start");
@@ -201,16 +201,16 @@ public class DebugEvents {
TestMod.SINK.accept(player.getScoreboardName() + " was awarded with %s" + logSide(player.level()), Advancement.name(advancement));
});
PlayerEvent.CRAFT_ITEM.register((player, constructed, inventory) -> {
TestMod.SINK.accept(player.getScoreboardName() + " crafts " + Component.translatable(constructed.getDescriptionId()).getString() + logSide(player.level()));
TestMod.SINK.accept(player.getScoreboardName() + " crafts " + Component.translatable(constructed.getItem().getDescriptionId()).getString() + logSide(player.level()));
});
PlayerEvent.SMELT_ITEM.register((player, smelted) -> {
TestMod.SINK.accept(player.getScoreboardName() + " smelts " + Component.translatable(smelted.getDescriptionId()).getString() + logSide(player.level()));
TestMod.SINK.accept(player.getScoreboardName() + " smelts " + Component.translatable(smelted.getItem().getDescriptionId()).getString() + logSide(player.level()));
});
PlayerEvent.PICKUP_ITEM_POST.register((player, entity, stack) -> {
TestMod.SINK.accept(player.getScoreboardName() + " picks up " + Component.translatable(stack.getDescriptionId()).getString() + logSide(player.level()));
TestMod.SINK.accept(player.getScoreboardName() + " picks up " + Component.translatable(stack.getItem().getDescriptionId()).getString() + logSide(player.level()));
});
PlayerEvent.DROP_ITEM.register((player, entity) -> {
TestMod.SINK.accept(player.getScoreboardName() + " drops " + Component.translatable(entity.getItem().getDescriptionId()).getString() + logSide(player.level()));
TestMod.SINK.accept(player.getScoreboardName() + " drops " + Component.translatable(entity.getItem().getItem().getDescriptionId()).getString() + logSide(player.level()));
return EventResult.pass();
});
PlayerEvent.OPEN_MENU.register((player, menu) -> {
@@ -224,15 +224,15 @@ public class DebugEvents {
});
PlayerEvent.FILL_BUCKET.register(((player, level, stack, target) -> {
TestMod.SINK.accept("%s used a bucket (%s) in %s%s while looking at %s", player.getScoreboardName(), stack, level.dimension().location(), logSide(level), target == null ? "nothing" : target.getLocation());
return CompoundEventResult.pass();
return InteractionResult.PASS;
}));
LightningEvent.STRIKE.register((bolt, level, pos, toStrike) -> {
TestMod.SINK.accept(bolt.getScoreboardName() + " struck at " + toShortString(pos) + logSide(level));
});
ChunkEvent.LOAD_DATA.register((chunk, level, nbt) -> {
ChunkEvent.LOAD_DATA.register((chunk, level) -> {
// TestMod.SINK.accept("Chunk loaded at x=" + chunk.getPos().x + ", z=" + chunk.getPos().z + " in dimension '" + level.dimension().location() + "'");
});
ChunkEvent.SAVE_DATA.register((chunk, level, nbt) -> {
ChunkEvent.SAVE_DATA.register((chunk, level) -> {
// TestMod.SINK.accept("Chunk saved at x=" + chunk.getPos().x + ", z=" + chunk.getPos().z + " in dimension '" + level.dimension().location() + "'");
});
}
@@ -359,11 +359,6 @@ public class DebugEvents {
TestMod.SINK.accept("Screen has been changed to " + toSimpleName(screen));
return CompoundEventResult.pass();
});
ClientTooltipEvent.RENDER_MODIFY_COLOR.register((matrices, x, y, context) -> {
context.setBackgroundColor(0xf0ffeded);
context.setOutlineGradientTopColor(0xf0ff5c5c);
context.setOutlineGradientBottomColor(0xf0f74d4d);
});
}
private static String chunkPos(int x, int z) {

View File

@@ -41,7 +41,7 @@ public final class TestBlockInteractions {
if (!ctx.getLevel().isClientSide) {
Player player = ctx.getPlayer();
if (player != null)
player.sendSystemMessage(Component.literal("Thou has successfully committed the dark arts of alchemy!!"));
player.displayClientMessage(Component.literal("Thou has successfully committed the dark arts of alchemy!!"), false);
}
}, ctx -> {
return Blocks.DIAMOND_BLOCK.defaultBlockState();

View File

@@ -51,6 +51,6 @@ public class ButtonClickedMessage extends BaseC2SMessage {
@Override
public void handle(NetworkManager.PacketContext context) {
context.getPlayer().sendSystemMessage(Component.literal("You clicked button #" + buttonId));
context.getPlayer().displayClientMessage(Component.literal("You clicked button #" + buttonId), false);
}
}

View File

@@ -54,6 +54,6 @@ public class SyncDataMessage extends BaseS2CMessage {
@Override
public void handle(NetworkManager.PacketContext context) {
context.getPlayer().sendSystemMessage(Component.literal("Received data from server: " + serverData));
context.getPlayer().displayClientMessage(Component.literal("Received data from server: " + serverData), false);
}
}

View File

@@ -22,7 +22,6 @@ package dev.architectury.test.registry;
import dev.architectury.core.fluid.ArchitecturyFluidAttributes;
import dev.architectury.core.fluid.SimpleArchitecturyFluidAttributes;
import dev.architectury.core.item.ArchitecturySpawnEggItem;
import dev.architectury.hooks.item.food.FoodPropertiesHooks;
import dev.architectury.hooks.level.entity.EntityHooks;
import dev.architectury.platform.Platform;
import dev.architectury.registry.CreativeTabRegistry;
@@ -37,8 +36,10 @@ import dev.architectury.test.recipes.TestRecipeSerializer;
import dev.architectury.test.registry.objects.EquippableTickingItem;
import dev.architectury.test.registry.objects.ItemWithTooltip;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
@@ -49,6 +50,8 @@ import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.Consumables;
import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
@@ -64,6 +67,7 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.function.Supplier;
import static dev.architectury.test.TestMod.SINK;
@@ -109,27 +113,32 @@ public class TestRegistries {
});
public static final RegistrySupplier<Item> TEST_ITEM = ITEMS.register("test_item", () ->
new Item(new Item.Properties().arch$tab(TestRegistries.TEST_TAB)));
new Item(new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "test_item"))));
public static final RegistrySupplier<Item> TEST_EQUIPPABLE = ITEMS.register("test_eqippable", () ->
new EquippableTickingItem(new Item.Properties().arch$tab(TestRegistries.TEST_TAB)));
new EquippableTickingItem(new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "test_eqippable"))));
public static final RegistrySupplier<Item> TEST_EDIBLE = ITEMS.register("test_edible", () -> {
FoodProperties.Builder fpBuilder = new FoodProperties.Builder().nutrition(8).saturationModifier(0.8F);
FoodPropertiesHooks.effect(fpBuilder, () -> new MobEffectInstance(TEST_EFFECT, 100), 1);
return new Item(new Item.Properties().food(fpBuilder.build()).arch$tab(TestRegistries.TEST_TAB));
return new Item(new Item.Properties()
.food(new FoodProperties.Builder().nutrition(8).saturationModifier(0.8F).build(),
Consumables.defaultFood()
.onConsume(
new ApplyStatusEffectsConsumeEffect(List.of(new MobEffectInstance(TEST_EFFECT, 100, 1)))
).build())
.arch$tab(TestRegistries.TEST_TAB)
.setId(id(Registries.ITEM, "test_edible")));
});
public static final RegistrySupplier<Item> TEST_SPAWN_EGG = ITEMS.register("test_spawn_egg", () ->
new ArchitecturySpawnEggItem(TestRegistries.TEST_ENTITY, 0xFF000000, 0xFFFFFFFF,
new Item.Properties().arch$tab(TestRegistries.TEST_TAB)));
new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "test_spawn_egg"))));
public static final RegistrySupplier<Item> TEST_SPAWN_EGG_2 = ITEMS.register("test_spawn_egg_2", () ->
new ArchitecturySpawnEggItem(TestRegistries.TEST_ENTITY_2, 0xFFFFFFFF, 0xFF000000,
new Item.Properties().arch$tab(TestRegistries.TEST_TAB)));
new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "test_spawn_egg_2"))));
public static final RegistrySupplier<Item> TEST_FLUID_BUCKET = ITEMS.register("test_fluid_bucket", () -> {
try {
// In example mod the forge class isn't being replaced, this is not required in mods depending on architectury
return (Item) Class.forName(!Platform.isForge() ? "dev.architectury.core.item.ArchitecturyBucketItem" : "dev.architectury.core.item.forge.imitator.ArchitecturyBucketItem")
.getDeclaredConstructor(Supplier.class, Item.Properties.class)
.newInstance(TestRegistries.TEST_FLUID, new Item.Properties().arch$tab(TestRegistries.TEST_TAB));
.newInstance(TestRegistries.TEST_FLUID, new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "test_fluid_bucket")));
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) {
throw new RuntimeException(e);
@@ -137,12 +146,12 @@ public class TestRegistries {
});
public static final RegistrySupplier<ItemWithTooltip> TEST_TOOLTIP = ITEMS.register("test_tooltip",
() -> new ItemWithTooltip(new Item.Properties().arch$tab(TestRegistries.TEST_TAB)));
() -> new ItemWithTooltip(new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "test_tooltip"))));
public static final RegistrySupplier<Block> TEST_BLOCK = BLOCKS.register("test_block", () ->
new Block(BlockBehaviour.Properties.ofLegacyCopy(Blocks.STONE)));
new Block(BlockBehaviour.Properties.ofLegacyCopy(Blocks.STONE).setId(id(Registries.BLOCK, "test_block"))));
public static final RegistrySupplier<Block> COLLISION_BLOCK = BLOCKS.register("collision_block", () ->
new Block(BlockBehaviour.Properties.ofLegacyCopy(Blocks.STONE)) {
new Block(BlockBehaviour.Properties.ofLegacyCopy(Blocks.STONE).setId(id(Registries.BLOCK, "collision_block"))) {
@Override
public VoxelShape getCollisionShape(BlockState state, BlockGetter bg, BlockPos pos, CollisionContext ctx) {
SINK.accept(EntityHooks.fromCollision(ctx) + " is colliding with " + state);
@@ -155,7 +164,7 @@ public class TestRegistries {
// In example mod the forge class isn't being replaced, this is not required in mods depending on architectury
return (LiquidBlock) Class.forName(!Platform.isForge() ? "dev.architectury.core.block.ArchitecturyLiquidBlock" : "dev.architectury.core.block.forge.imitator.ArchitecturyLiquidBlock")
.getDeclaredConstructor(Supplier.class, BlockBehaviour.Properties.class)
.newInstance(TestRegistries.TEST_FLUID, BlockBehaviour.Properties.ofLegacyCopy(Blocks.WATER).noCollission().strength(100.0F).noLootTable());
.newInstance(TestRegistries.TEST_FLUID, BlockBehaviour.Properties.ofLegacyCopy(Blocks.WATER).noCollission().strength(100.0F).noLootTable().setId(id(Registries.BLOCK, "test_fluid")));
} catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) {
throw new RuntimeException(e);
@@ -187,9 +196,9 @@ public class TestRegistries {
});
public static final RegistrySupplier<Item> TEST_BLOCK_ITEM = ITEMS.register("test_block", () ->
new BlockItem(TEST_BLOCK.get(), new Item.Properties().arch$tab(TestRegistries.TEST_TAB)));
new BlockItem(TEST_BLOCK.get(), new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "test_block"))));
public static final RegistrySupplier<Item> COLLISION_BLOCK_ITEM = ITEMS.register("collision_block", () ->
new BlockItem(COLLISION_BLOCK.get(), new Item.Properties().arch$tab(TestRegistries.TEST_TAB)));
new BlockItem(COLLISION_BLOCK.get(), new Item.Properties().arch$tab(TestRegistries.TEST_TAB).setId(id(Registries.ITEM, "collision_block"))));
public static final RegistrySupplier<EntityType<TestEntity>> TEST_ENTITY = ENTITY_TYPES.register("test_entity", TestEntity.TYPE);
public static final RegistrySupplier<EntityType<TestEntity>> TEST_ENTITY_2 = ENTITY_TYPES.register("test_entity_2", TestEntity.TYPE_2);
@@ -224,4 +233,8 @@ public class TestRegistries {
System.out.println("Registered recipe type!");
});
}
private static <T> ResourceKey<T> id(ResourceKey<Registry<T>> key, String string) {
return ResourceKey.create(key, ResourceLocation.fromNamespaceAndPath(TestMod.MOD_ID, string));
}
}

View File

@@ -35,7 +35,7 @@ public class EquippableTickingItem extends Item implements ItemExtension {
@Override
public void tickArmor(ItemStack stack, Player player) {
TestMod.SINK.accept("Ticking " + Component.translatable(stack.getDescriptionId()).getString());
TestMod.SINK.accept("Ticking " + Component.translatable(stack.getItem().getDescriptionId()).getString());
}
@Nullable

View File

@@ -42,13 +42,13 @@ public class ItemWithTooltip extends Item {
}
public record MyTooltipComponent(int count) implements TooltipComponent {
}
@Environment(EnvType.CLIENT)
public record MyClientTooltipComponent(MyTooltipComponent component) implements ClientTooltipComponent {
@Override
public int getHeight() {
public int getHeight(Font font) {
return 100;
}
@@ -58,10 +58,10 @@ public class ItemWithTooltip extends Item {
}
@Override
public void renderImage(Font font, int x, int y, GuiGraphics graphics) {
public void renderImage(Font font, int x, int y, int w, int h, GuiGraphics graphics) {
graphics.pose().pushPose();
graphics.pose().translate(0, 0, 400);
graphics.drawString(font, "Count: " + component.count, x + getWidth(font) / 2, y + (getHeight() - font.lineHeight) / 2, 0xFF00FF00);
graphics.drawString(font, "Count: " + component.count, x + getWidth(font) / 2, y + (getHeight(font) - font.lineHeight) / 2, 0xFF00FF00);
graphics.pose().popPose();
}
}

View File

@@ -18,9 +18,6 @@
"net/minecraft/class_1755": [
"dev/architectury/extensions/injected/InjectedBucketItemExtension"
],
"net/minecraft/class_4174$class_4175": [
"dev/architectury/extensions/injected/InjectedFoodPropertiesBuilderExtension"
],
"net/minecraft/class_2404": [
"dev/architectury/extensions/injected/InjectedLiquidBlockExtension"
]