Skip to content

Commit

Permalink
Merge pull request #56 from cdqtzrc/fabric/1.21
Browse files Browse the repository at this point in the history
更新到1.21
  • Loading branch information
Gu-ZT authored Jun 21, 2024
2 parents d025af7 + 6b35988 commit 0ed4f79
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 219 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.1
loader_version=0.14.21
minecraft_version=1.21
loader_version=0.15.11
# parchment_version=2022.08.14
# Mod Properties
mod_version=2.8.0
build_number=undefined
maven_group=dev.dubhe.gugle
archives_base_name=gugle-carpet-addition

carpet_core_version=4573334
carpet_core_version=5425253

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 5 additions & 11 deletions src/main/java/dev/dubhe/gugle/carpet/GcaExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import dev.dubhe.gugle.carpet.api.Function;
import dev.dubhe.gugle.carpet.api.Consumer;
import dev.dubhe.gugle.carpet.api.tools.text.ComponentTranslate;
import dev.dubhe.gugle.carpet.tools.FakePlayerEnderChestContainer;
import dev.dubhe.gugle.carpet.tools.FakePlayerInventoryContainer;
Expand Down Expand Up @@ -40,12 +40,12 @@ public class GcaExtension implements CarpetExtension, ModInitializer {
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public static @NotNull ResourceLocation id(String path) {
return new ResourceLocation(MOD_ID, path);
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
}

public static final HashMap<Player, Map.Entry<FakePlayerInventoryContainer, FakePlayerEnderChestContainer>> fakePlayerInventoryContainerMap = new HashMap<>();

public static final List<Map.Entry<Long, Function>> planFunction = new ArrayList<>();
public static final List<Map.Entry<Long, Consumer>> planFunction = new ArrayList<>();

static {
CarpetServer.manageExtension(new GcaExtension());
Expand All @@ -54,7 +54,7 @@ public class GcaExtension implements CarpetExtension, ModInitializer {
@Override
public void onPlayerLoggedIn(ServerPlayer player) {
GcaExtension.fakePlayerInventoryContainerMap.put(player, Map.entry(
new FakePlayerInventoryContainer(player), new FakePlayerEnderChestContainer(player)
new FakePlayerInventoryContainer(player), new FakePlayerEnderChestContainer(player)
));
}

Expand All @@ -77,13 +77,7 @@ public static void onServerStop(MinecraftServer server) {
fakePlayerList.add(username, FakePlayerResident.save(player));
});
File file = server.getWorldPath(LevelResource.ROOT).resolve("fake_player.gca.json").toFile();
if (!file.isFile()) {
try {
file.createNewFile();
} catch (IOException e) {
GcaExtension.LOGGER.error(e.getMessage(), e);
}
}
// 文件不需要存在
try (BufferedWriter bfw = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
bfw.write(GSON.toJson(fakePlayerList));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.dubhe.gugle.carpet.api;

@FunctionalInterface
public interface Function {

public interface Consumer {
void accept();
}
50 changes: 26 additions & 24 deletions src/main/java/dev/dubhe/gugle/carpet/api/menu/control/Button.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package dev.dubhe.gugle.carpet.api.menu.control;

import dev.dubhe.gugle.carpet.api.Function;
import dev.dubhe.gugle.carpet.api.Consumer;
import dev.dubhe.gugle.carpet.api.tools.text.Color;
import dev.dubhe.gugle.carpet.api.tools.text.ComponentTranslate;
import net.minecraft.core.component.DataComponents;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.world.Container;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.CustomData;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -23,9 +25,9 @@ public class Button {
private final ItemStack offItem;
CompoundTag compoundTag = new CompoundTag();

private final List<Function> turnOnFunctions = new ArrayList<>();
private final List<Consumer> turnOnConsumers = new ArrayList<>();

private final List<Function> turnOffFunctions = new ArrayList<>();
private final List<Consumer> turnOffConsumers = new ArrayList<>();

public Button() {
this(true, Items.BARRIER, Items.STRUCTURE_VOID);
Expand All @@ -49,8 +51,8 @@ public Button(boolean defaultState, Component onText, Component offText) {

public Button(boolean defaultState, String key) {
this(defaultState, Items.BARRIER, Items.STRUCTURE_VOID, 1,
ComponentTranslate.trans(key, Color.GREEN, Style.EMPTY.withBold(true).withItalic(false), ComponentTranslate.trans("gca.button.on")),
ComponentTranslate.trans(key, Color.RED, Style.EMPTY.withBold(true).withItalic(false), ComponentTranslate.trans("gca.button.off"))
ComponentTranslate.trans(key, Color.GREEN, Style.EMPTY.withBold(true).withItalic(false), ComponentTranslate.trans("gca.button.on")),
ComponentTranslate.trans(key, Color.RED, Style.EMPTY.withBold(true).withItalic(false), ComponentTranslate.trans("gca.button.off"))
);
}

Expand All @@ -60,8 +62,8 @@ public Button(boolean defaultState, Item onItem, Item offItem) {

public Button(boolean defaultState, Item onItem, Item offItem, int itemCount) {
this(defaultState, onItem, offItem, itemCount,
ComponentTranslate.trans("gca.button.on", Color.GREEN, Style.EMPTY.withBold(true).withItalic(false)),
ComponentTranslate.trans("gca.button.off", Color.RED, Style.EMPTY.withBold(true).withItalic(false))
ComponentTranslate.trans("gca.button.on", Color.GREEN, Style.EMPTY.withBold(true).withItalic(false)),
ComponentTranslate.trans("gca.button.off", Color.RED, Style.EMPTY.withBold(true).withItalic(false))
);
}

Expand All @@ -70,13 +72,13 @@ public Button(boolean defaultState, Item onItem, Item offItem, int itemCount, Co
this.compoundTag.putBoolean("GcaClear", true);

ItemStack onItemStack = new ItemStack(onItem, itemCount);
onItemStack.setTag(compoundTag.copy());
onItemStack.setHoverName(onText);
onItemStack.set(DataComponents.CUSTOM_DATA, CustomData.of(compoundTag));
onItemStack.set(DataComponents.ITEM_NAME, onText);
this.onItem = onItemStack;

ItemStack offItemStack = new ItemStack(offItem, itemCount);
offItemStack.setTag(compoundTag.copy());
offItemStack.setHoverName(offText);
offItemStack.set(DataComponents.CUSTOM_DATA, CustomData.of(compoundTag.copy()));
offItemStack.set(DataComponents.ITEM_NAME, offText);
this.offItem = offItemStack;
}

Expand All @@ -85,11 +87,11 @@ public Button(boolean defaultState, @NotNull ItemStack onItem, @NotNull ItemStac
this.compoundTag.putBoolean("GcaClear", true);

ItemStack onItemStack = onItem.copy();
onItemStack.setTag(compoundTag.copy());
onItemStack.set(DataComponents.CUSTOM_DATA, CustomData.of(compoundTag.copy()));
this.onItem = onItemStack;

ItemStack offItemStack = offItem.copy();
offItemStack.setTag(compoundTag.copy());
offItemStack.set(DataComponents.CUSTOM_DATA, CustomData.of(compoundTag.copy()));
this.offItem = offItemStack;
}

Expand Down Expand Up @@ -117,9 +119,9 @@ public void checkButton(Container container, int slot) {

public void updateButton(@NotNull Container container, int slot, @NotNull ItemStack onItemStack, ItemStack offItemStack) {
if (!(
container.getItem(slot).is(onItemStack.getItem()) ||
container.getItem(slot).is(offItemStack.getItem()) ||
container.getItem(slot).isEmpty()
container.getItem(slot).is(onItemStack.getItem()) ||
container.getItem(slot).is(offItemStack.getItem()) ||
container.getItem(slot).isEmpty()
)) {
return;
}
Expand All @@ -130,12 +132,12 @@ public void updateButton(@NotNull Container container, int slot, @NotNull ItemSt
}
}

public void addTurnOnFunction(Function function) {
this.turnOnFunctions.add(function);
public void addTurnOnFunction(Consumer consumer) {
this.turnOnConsumers.add(consumer);
}

public void addTurnOffFunction(Function function) {
this.turnOffFunctions.add(function);
public void addTurnOffFunction(Consumer consumer) {
this.turnOffConsumers.add(consumer);
}

public void turnOnWithoutFunction() {
Expand All @@ -157,14 +159,14 @@ public void turnOff() {
}

public void runTurnOnFunction() {
for (Function turnOnFunction : this.turnOnFunctions) {
turnOnFunction.accept();
for (Consumer turnOnConsumer : this.turnOnConsumers) {
turnOnConsumer.accept();
}
}

public void runTurnOffFunction() {
for (Function turnOffFunction : this.turnOffFunctions) {
turnOffFunction.accept();
for (Consumer turnOffConsumer : this.turnOffConsumers) {
turnOffConsumer.accept();
}
}

Expand Down
33 changes: 17 additions & 16 deletions src/main/java/dev/dubhe/gugle/carpet/api/tools/text/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@

import net.minecraft.network.chat.TextColor;

@SuppressWarnings("unused")
public class Color {

public static final TextColor BLACK = TextColor.parseColor("#000000");
public static final TextColor BLACK = TextColor.parseColor("#000000").getOrThrow();

public static final TextColor DARK_BLUE = TextColor.parseColor("#0000AA");
public static final TextColor DARK_BLUE = TextColor.parseColor("#0000AA").getOrThrow();

public static final TextColor DARK_GREEN = TextColor.parseColor("#00AA00");
public static final TextColor DARK_GREEN = TextColor.parseColor("#00AA00").getOrThrow();

public static final TextColor DARK_AQUA = TextColor.parseColor("#00AAAA");
public static final TextColor DARK_AQUA = TextColor.parseColor("#00AAAA").getOrThrow();

public static final TextColor DARK_RED = TextColor.parseColor("#AA0000");
public static final TextColor DARK_RED = TextColor.parseColor("#AA0000").getOrThrow();

public static final TextColor DARK_PURPLE = TextColor.parseColor("#AA00AA");
public static final TextColor DARK_PURPLE = TextColor.parseColor("#AA00AA").getOrThrow();

public static final TextColor GOLD = TextColor.parseColor("#FFAA00");
public static final TextColor GOLD = TextColor.parseColor("#FFAA00").getOrThrow();

public static final TextColor GARY = TextColor.parseColor("#AAAAAA");
public static final TextColor GARY = TextColor.parseColor("#AAAAAA").getOrThrow();

public static final TextColor DARK_GARY = TextColor.parseColor("#555555");
public static final TextColor DARK_GARY = TextColor.parseColor("#555555").getOrThrow();

public static final TextColor BLUE = TextColor.parseColor("#5555FF");
public static final TextColor BLUE = TextColor.parseColor("#5555FF").getOrThrow();

public static final TextColor GREEN = TextColor.parseColor("#55FF55");
public static final TextColor GREEN = TextColor.parseColor("#55FF55").getOrThrow();

public static final TextColor AQUA = TextColor.parseColor("#55FFFF");
public static final TextColor AQUA = TextColor.parseColor("#55FFFF").getOrThrow();

public static final TextColor RED = TextColor.parseColor("#FF5555");
public static final TextColor RED = TextColor.parseColor("#FF5555").getOrThrow();

public static final TextColor LIGHT_PURPLE = TextColor.parseColor("#FF55FF");
public static final TextColor LIGHT_PURPLE = TextColor.parseColor("#FF55FF").getOrThrow();

public static final TextColor YELLOW = TextColor.parseColor("#FFFF55");
public static final TextColor YELLOW = TextColor.parseColor("#FFFF55").getOrThrow();

public static final TextColor WHITE = TextColor.parseColor("#FFFFFF");
public static final TextColor WHITE = TextColor.parseColor("#FFFFFF").getOrThrow();

private Color() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.dubhe.gugle.carpet.mixin;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.CustomData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -14,20 +16,22 @@
@Mixin(AbstractContainerMenu.class)
abstract class AbstractContainerMenuMixin {
@Unique
AbstractContainerMenu gca$self = (AbstractContainerMenu)(Object)this;
private final AbstractContainerMenu gca$self = (AbstractContainerMenu) (Object) this;

@Inject(method = "doClick", at = @At("HEAD"), cancellable = true)
private void doClick(int mouseX, int mouseY, ClickType clickType, Player player, CallbackInfo ci) {
if (mouseX < 0) return;
Slot slot = gca$self.getSlot(mouseX);
private void doClick(int slotIndex, int button, ClickType clickType, Player player, CallbackInfo ci) {
if (slotIndex < 0) {
return;
}
Slot slot = gca$self.getSlot(slotIndex);
ItemStack itemStack = slot.getItem();
if (itemStack.getTag() != null) {
if (itemStack.getTag().get("GcaClear") != null) {
if (itemStack.getTag().getBoolean("GcaClear")) {
itemStack.setCount(0);
ci.cancel();
}
}
CustomData customData = itemStack.get(DataComponents.CUSTOM_DATA);
if (customData == null || customData.copyTag().get("GcaClear") == null) {
return;
}
if (customData.copyTag().getBoolean("GcaClear")) {
itemStack.setCount(0);
ci.cancel();
}
}
}
7 changes: 5 additions & 2 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/AxeItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

@Mixin(AxeItem.class)
abstract class AxeItemMixin {
@Inject(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/AxeItem;getStripped(Lnet/minecraft/world/level/block/state/BlockState;)Ljava/util/Optional;"), cancellable = true)
@Inject(method = "useOn", at = @At(value = "HEAD"), cancellable = true)
private void stripped(@NotNull UseOnContext context, CallbackInfoReturnable<InteractionResult> cir) {
ItemStack itemStack = context.getItemInHand();
String name = itemStack.getHoverName().getString();
if (!name.contains("Strip") && !name.contains("去皮") && GcaSetting.betterWoodStrip) {
if (GcaSetting.betterWoodStrip) {
if (name.contains("Strip") || name.contains("去皮")) {
return;
}
cir.setReturnValue(InteractionResult.PASS);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/EntityInvoker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.dubhe.gugle.carpet.mixin;

import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(Entity.class)
public interface EntityInvoker {
@Invoker("unsetRemoved")
void invokerUnsetRemoved();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dev.dubhe.gugle.carpet.mixin;

import carpet.patches.EntityPlayerMPFake;
import com.mojang.authlib.GameProfile;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.util.Optional;
import java.util.concurrent.CompletableFuture;

@Mixin(EntityPlayerMPFake.class)
public interface EntityPlayerMPFakeInvoker {
@Invoker(value = "fetchGameProfile", remap = false)
static CompletableFuture<Optional<GameProfile>> invokerFetchGameProfile(String name) {
throw new AssertionError();
}
}
Loading

0 comments on commit 0ed4f79

Please sign in to comment.