24w40a
This commit is contained in:
1 parent
6144967299
commit
3a66dd0a9b
17 files changed
+269
-232
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.AbstractContainerMenuInterface;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractCraftingMenu;
|
||||
@@ -15,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
public class AbstractCraftingMenu_scarpetMixin
|
||||
{
|
||||
@Inject(method = "handlePlacement",at = @At("HEAD"), cancellable = true)
|
||||
private void selectRecipeCallback(boolean craftAll, boolean b, RecipeHolder<?> recipe, Inventory player, CallbackInfoReturnable<RecipeBookMenu.PostPlaceAction> cir) {
|
||||
private void selectRecipeCallback(boolean craftAll, boolean b, RecipeHolder<?> recipe, ServerLevel serverLevel, Inventory player, CallbackInfoReturnable<RecipeBookMenu.PostPlaceAction> cir) {
|
||||
if(((AbstractContainerMenuInterface) this).callSelectRecipeListener((ServerPlayer) player.player ,recipe,craftAll))
|
||||
cir.setReturnValue(RecipeBookMenu.PostPlaceAction.NOTHING);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.AbstractContainerMenuInterface;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.AbstractFurnaceMenu;
|
||||
@@ -15,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
public class AbstractFurnaceMenu_scarpetMixin
|
||||
{
|
||||
@Inject(method = "handlePlacement",at = @At("HEAD"), cancellable = true)
|
||||
private void selectRecipeCallback(boolean craftAll, boolean b, RecipeHolder<?> recipe, Inventory player, CallbackInfoReturnable<RecipeBookMenu.PostPlaceAction> cir) {
|
||||
private void selectRecipeCallback(boolean craftAll, boolean b, RecipeHolder<?> recipe, ServerLevel level, Inventory player, CallbackInfoReturnable<RecipeBookMenu.PostPlaceAction> cir) {
|
||||
if(((AbstractContainerMenuInterface) this).callSelectRecipeListener((ServerPlayer) player.player ,recipe,craftAll))
|
||||
cir.setReturnValue(RecipeBookMenu.PostPlaceAction.NOTHING);
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.RecipeManagerInterface;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
|
||||
@Mixin(RecipeManager.class)
|
||||
public class RecipeManager_scarpetMixin implements RecipeManagerInterface
|
||||
{
|
||||
@Shadow private Multimap<RecipeType<?>, RecipeHolder<?>> byType;
|
||||
|
||||
@Shadow private Map<ResourceLocation, RecipeHolder<?>> byName;
|
||||
|
||||
@Override
|
||||
public List<Recipe<?>> getAllMatching(RecipeType<?> type, ResourceLocation itemId, RegistryAccess registryAccess)
|
||||
{
|
||||
// quiq cheq
|
||||
RecipeHolder<?> recipe = byName.get(itemId);
|
||||
if (recipe != null && recipe.value().getType().equals(type))
|
||||
{
|
||||
return List.of(recipe.value());
|
||||
}
|
||||
if (!byType.containsKey(type))
|
||||
{
|
||||
// happens when mods add recipe to the registry without updating recipe manager
|
||||
return List.of();
|
||||
}
|
||||
Collection<RecipeHolder<?>> typeRecipes = byType.get(type);
|
||||
Registry<Item> regs = registryAccess.lookupOrThrow(Registries.ITEM);
|
||||
Item item = regs.getValue(itemId);
|
||||
if (item == Items.AIR)
|
||||
{
|
||||
return List.of();
|
||||
}
|
||||
return typeRecipes.stream()
|
||||
.<Recipe<?>>map(RecipeHolder::value)
|
||||
.filter(r -> r.getResultItem(registryAccess).is(item))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package carpet.mixins;
|
||||
import carpet.fakes.EntityInterface;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
|
||||
import net.minecraft.world.entity.player.Input;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@@ -255,7 +256,11 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
||||
{
|
||||
if (PLAYER_CHOOSES_RECIPE.isNeeded())
|
||||
{
|
||||
if(PLAYER_CHOOSES_RECIPE.onRecipeSelected(player, packet.getRecipe(), packet.isUseMaxItems())) ci.cancel();
|
||||
RecipeManager.ServerDisplayInfo displayInfo = player.server.getRecipeManager().getRecipeFromDisplay(packet.recipe());
|
||||
if (displayInfo == null) {
|
||||
return;
|
||||
}
|
||||
if(PLAYER_CHOOSES_RECIPE.onRecipeSelected(player, displayInfo.parent().id().location(), packet.useMaxItems())) ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.portal.DimensionTransition;
|
||||
import net.minecraft.world.level.portal.TeleportTransition;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -86,20 +86,20 @@ public abstract class ServerPlayer_scarpetEventMixin extends Player implements S
|
||||
private Vec3 previousLocation;
|
||||
private ResourceKey<Level> previousDimension;
|
||||
|
||||
@Inject(method = "changeDimension", at = @At("HEAD"))
|
||||
private void logPreviousCoordinates(DimensionTransition serverWorld, CallbackInfoReturnable<Entity> cir)
|
||||
@Inject(method = "teleport", at = @At("HEAD"))
|
||||
private void logPreviousCoordinates(TeleportTransition serverWorld, CallbackInfoReturnable<Entity> cir)
|
||||
{
|
||||
previousLocation = position();
|
||||
previousDimension = level().dimension(); //dimension type
|
||||
}
|
||||
|
||||
@Inject(method = "changeDimension", at = @At("RETURN"))
|
||||
private void atChangeDimension(DimensionTransition destinationP, CallbackInfoReturnable<Entity> cir)
|
||||
@Inject(method = "teleport", at = @At("RETURN"))
|
||||
private void atChangeDimension(TeleportTransition destinationP, CallbackInfoReturnable<Entity> cir)
|
||||
{
|
||||
if (PLAYER_CHANGES_DIMENSION.isNeeded())
|
||||
{
|
||||
ServerPlayer player = (ServerPlayer) (Object)this;
|
||||
DimensionTransition destinationTransition = destinationP;
|
||||
TeleportTransition destinationTransition = destinationP;
|
||||
ServerLevel destination = destinationTransition.newLevel();
|
||||
Vec3 to = null;
|
||||
if (!wonGame || previousDimension != Level.END || destination.dimension() != Level.OVERWORLD)
|
||||
|
||||
Reference in new issue
Block a user