Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.21 Support #17

Open
wants to merge 2 commits into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Click Opener Mod
# Click Opener Continued
Fork of [Click Opener Mod](https://github.com/RealMegaMinds/ClickOpener) by [Hoid2](https://github.com/hoid2).

Created with permission from the original author.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version
Expand Down Expand Up @@ -38,7 +38,7 @@ processResources {

tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
it.options.release = 21
}

java {
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.15.7
# check these on https://fabricmc.net/develop
minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.15.11

# Mod Properties
mod_version = 4.0.1-alpha+1.20.1
maven_group = megaminds.clickopener
archives_base_name = clickopener
mod_version = 1.0.0+1.21
maven_group = pw.smto
archives_base_name = clickopener

# Dependencies
fabric_version=0.91.1+1.20.1
fabric_version=0.100.7+1.21
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener;
package pw.smto.clickopener;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
Expand All @@ -10,8 +10,8 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import megaminds.clickopener.api.OpenerRegistry;
import megaminds.clickopener.util.IdentifierAdapter;
import pw.smto.clickopener.api.OpenerRegistry;
import pw.smto.clickopener.util.IdentifierAdapter;

//When using item on block, check item is allowed
//Add option for ticking screenhandler when itemstack ticks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package megaminds.clickopener;
package pw.smto.clickopener;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;

import megaminds.clickopener.api.ClickType;
import megaminds.clickopener.interfaces.ArgumentChecker;
import pw.smto.clickopener.api.ClickType;
import pw.smto.clickopener.interfaces.ArgumentChecker;

import static net.minecraft.server.command.CommandManager.literal;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener;
package pw.smto.clickopener;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -10,7 +10,7 @@
import com.google.gson.JsonIOException;
import com.google.gson.JsonParseException;

import megaminds.clickopener.api.ClickType;
import pw.smto.clickopener.api.ClickType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.item.BlockItem;
Expand Down Expand Up @@ -188,9 +188,9 @@ public void fill(Config config) {
for (var s : whitelist) {
var arr = s.split("#",2);
if (arr.length == 1) {
config.itemList.add(new Identifier(s));
config.itemList.add(Identifier.of(s));
} else if (arr.length == 2) {
var id = new Identifier(arr[1]);
var id = Identifier.of(arr[1]);
if (!arr[0].equals("item")) {
config.blockTagsList.add(TagKey.of(RegistryKeys.BLOCK, id));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener;
package pw.smto.clickopener;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -12,7 +12,7 @@
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;

import megaminds.clickopener.api.ClickType;
import pw.smto.clickopener.api.ClickType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.network.ServerPlayerEntity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.api;
package pw.smto.clickopener.api;

import java.util.Arrays;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package megaminds.clickopener.api;
package pw.smto.clickopener.api;

import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import megaminds.clickopener.impl.ClickContext;
import megaminds.clickopener.interfaces.Openable;
import pw.smto.clickopener.impl.ClickContext;
import pw.smto.clickopener.interfaces.Openable;
import net.minecraft.item.ItemStack;

public abstract class OpenContext<SELF extends OpenContext<SELF, O>, O extends Opener<O, SELF>> extends ClickContext {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package megaminds.clickopener.api;
package pw.smto.clickopener.api;

import megaminds.clickopener.impl.ClickContext;
import megaminds.clickopener.interfaces.OpenContextHolder;
import megaminds.clickopener.interfaces.Openable;
import megaminds.clickopener.interfaces.UseAllower;
import pw.smto.clickopener.impl.ClickContext;
import pw.smto.clickopener.interfaces.OpenContextHolder;
import pw.smto.clickopener.interfaces.Openable;
import pw.smto.clickopener.interfaces.UseAllower;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.api;
package pw.smto.clickopener.api;

import java.util.function.BiConsumer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.api;
package pw.smto.clickopener.api;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package megaminds.clickopener.impl;
package pw.smto.clickopener.impl;

import java.util.Objects;

import megaminds.clickopener.api.OpenContext;
import megaminds.clickopener.util.FakeWorld;
import pw.smto.clickopener.api.OpenContext;
import pw.smto.clickopener.util.FakeWorld;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package megaminds.clickopener.impl;
package pw.smto.clickopener.impl;

import megaminds.clickopener.api.Opener;
import pw.smto.clickopener.api.Opener;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.ActionResult;

public interface BlockScreenOpener extends Opener<BlockScreenOpener, BlockOpenContext> {
Expand All @@ -29,7 +26,7 @@ default BlockOpenContext mutateContext(ClickContext clickContext) {
@Override
default ActionResult open(BlockOpenContext context) {
if (context.initialStack().getCount() != 1) return ActionResult.FAIL;
var result = context.getBlockState().onUse(context.world(), context.player(), context.hand(), context.hitResult());
var result = context.getBlockState().onUse(context.world(), context.player(), context.hitResult());
if (result.isAccepted()) {
return result;
}
Expand Down Expand Up @@ -68,26 +65,18 @@ default void onStateChange(BlockState oldState, BlockOpenContext context) {

default BlockState getBlockState(BlockOpenContext context) {
var block = Block.getBlockFromItem(context.getStack().getItem());
var nbt = context.getStack().getSubNbt(BlockItem.BLOCK_STATE_TAG_KEY);
if (nbt != null) {
nbt.putString("Name", Registries.BLOCK.getId(block).toString());
var state = NbtHelper.toBlockState(context.world().createCommandRegistryWrapper(RegistryKeys.BLOCK), context.getStack().getSubNbt(BlockItem.BLOCK_STATE_TAG_KEY));
if (!state.isAir()) return state;

if (context.getStack().getComponents().contains(DataComponentTypes.BLOCK_STATE)) {
return context.getStack().get(DataComponentTypes.BLOCK_STATE).applyToState(block.getDefaultState());
}

return block.getDefaultState();
}

default BlockEntity getBlockEntity(BlockOpenContext context) {
if (!(context.getBlockState().getBlock() instanceof BlockEntityProvider provider)) return null;

var blockEntity = provider.createBlockEntity(context.pos(), context.getBlockState());
var blockNbt = BlockItem.getBlockEntityNbt(context.getStack());
if (blockNbt != null) {
blockEntity.readNbt(blockNbt);
}
if (context.getStack().hasCustomName() && blockEntity instanceof LockableContainerBlockEntity lockable) {
lockable.setCustomName(context.getStack().getName());
}
if (blockEntity != null) blockEntity.readComponents(context.getStack());
return blockEntity;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package megaminds.clickopener.impl;
package pw.smto.clickopener.impl;

import megaminds.clickopener.api.ClickType;
import pw.smto.clickopener.api.ClickType;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package megaminds.clickopener.impl;
package pw.smto.clickopener.impl;

import megaminds.clickopener.api.OpenContext;
import pw.smto.clickopener.api.OpenContext;

public class ItemOpenContext extends OpenContext<ItemOpenContext, ItemScreenOpener> {
public ItemOpenContext(ClickContext context, ItemScreenOpener opener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package megaminds.clickopener.impl;
package pw.smto.clickopener.impl;

import megaminds.clickopener.api.Opener;
import pw.smto.clickopener.api.Opener;
import net.minecraft.util.ActionResult;

public interface ItemScreenOpener extends Opener<ItemScreenOpener, ItemOpenContext> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.interfaces;
package pw.smto.clickopener.interfaces;

import com.mojang.brigadier.context.CommandContext;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.interfaces;
package pw.smto.clickopener.interfaces;

public interface ClosePacketSkipper {
void clickopener$setSkipClosePacket(boolean skipClosePacket);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package megaminds.clickopener.interfaces;
package pw.smto.clickopener.interfaces;

import megaminds.clickopener.api.OpenContext;
import pw.smto.clickopener.api.OpenContext;

public interface OpenContextHolder {
void clickopener$setOpenContext(OpenContext<?, ?> openContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.interfaces;
package pw.smto.clickopener.interfaces;

import net.minecraft.item.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.interfaces;
package pw.smto.clickopener.interfaces;

public interface UseAllower {
void clickopener$allowUse();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.mixin;
package pw.smto.clickopener.mixin;

import java.util.Map;

Expand All @@ -8,7 +8,7 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.ParsedArgument;

import megaminds.clickopener.interfaces.ArgumentChecker;
import pw.smto.clickopener.interfaces.ArgumentChecker;

@Mixin(value = CommandContext.class, remap = false)
public abstract class CommandContextMixin implements ArgumentChecker {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.mixin;
package pw.smto.clickopener.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
Expand All @@ -7,7 +7,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import megaminds.clickopener.interfaces.UseAllower;
import pw.smto.clickopener.interfaces.UseAllower;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package megaminds.clickopener.mixin;
package pw.smto.clickopener.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -7,7 +7,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import megaminds.clickopener.interfaces.Openable;
import pw.smto.clickopener.interfaces.Openable;
import net.minecraft.item.ItemStack;

@Mixin(ItemStack.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package megaminds.clickopener.mixin;
package pw.smto.clickopener.mixin;

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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import megaminds.clickopener.api.OpenContext;
import megaminds.clickopener.api.Opener;
import megaminds.clickopener.interfaces.OpenContextHolder;
import pw.smto.clickopener.api.OpenContext;
import pw.smto.clickopener.api.Opener;
import pw.smto.clickopener.interfaces.OpenContextHolder;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.ScreenHandler;

Expand Down
Loading