Skip to content
Merged
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
22 changes: 11 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ plugins {
base
alias(libs.plugins.mod.dev.gradle)
id("io.github.jeadyx.sonatype-uploader").version("2.8")
id("dev.vfyjxf.modaccessor") version "1.1.1"
// id("dev.vfyjxf.modaccessor") version "1.1.1"
}
val mcVersion: String by rootProject
val mcVersionRange: String by rootProject
Expand Down Expand Up @@ -56,6 +56,7 @@ allprojects {
dirs(rootProject.file("libs"))
}
maven("https://maven.neoforged.net/releases")
maven("https://mvn.devos.one/snapshots")
maven("https://maven.ithundxr.dev/snapshots")
// maven("https://maven.creeperhost.net/")
}
Expand Down Expand Up @@ -91,7 +92,7 @@ val lib = libs

subprojects {
apply(plugin = lib.plugins.mod.dev.gradle.get().pluginId)
apply(plugin = "dev.vfyjxf.modaccessor")
//apply(plugin = "dev.vfyjxf.modaccessor")

val modId: String by project
val modName: String by project
Expand Down Expand Up @@ -253,12 +254,12 @@ subprojects {
neoForge.setAccessTransformers(atFile)
}

modAccessor {
createTransformConfiguration(configurations.getAt("compileOnly"))
if (atFile.readBytes().isNotEmpty()) {
accessTransformerFiles = rootProject.files("src/${modId}/resources/META-INF/accesstransformer.cfg")
}
}
// modAccessor {
// createTransformConfiguration(configurations.getAt("compileOnly"))
// if (atFile.readBytes().isNotEmpty()) {
// accessTransformerFiles = rootProject.files("src/${modId}/resources/META-INF/accesstransformer.cfg")
// }
// }

val projectNames = listOf(
"Deco",
Expand All @@ -268,12 +269,11 @@ subprojects {
)

dependencies {
val registrate = "accessCompileOnly"(
implementation(
group = "com.tterrag.registrate",
name = "Registrate",
version = "[MC1.21-1.3.0+55,)"
version = "[MC1.21-1.3.0,)"
)
runtimeOnly(registrate)
implementation(
group="dev.xkmc",
name= "l2serial",
Expand Down
2 changes: 1 addition & 1 deletion modules/Agricultural/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dependencies {
jarJar(
group = "com.tterrag.registrate",
name = "Registrate",
version = "[MC1.21-1.3.0+55,)"
version = "[MC1.21-1.3.0,)"
)
jarJar(
group="dev.xkmc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.polaris2023.ww_ag.common.block.entity;

import com.tterrag.registrate.util.nullness.NonNullConsumer;
import com.tterrag.registrate.util.nullness.NonNullUnaryOperator;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.PatchedDataComponentMap;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Consumer;

/**
* @author baka4n
* @code @Date 2025/7/14 22:46:12
*/
@SuppressWarnings({"unused", "LombokGetterMayBeUsed"})
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ComponentBlockEntity<T extends ComponentBlockEntity<T>> extends BlockEntity {

private final PatchedDataComponentMap components;

public ComponentBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
super(type, pos, blockState);
this.components = new PatchedDataComponentMap(createDefaultComponents());
}

private DataComponentMap createDefaultComponents() {
return DataComponentMap.builder().build();
}

public DataComponentMap getComponents() {
return components;
}

public T updateComponents(NonNullConsumer<PatchedDataComponentMap> map) {
map.accept(components);
setChanged();
if (level != null) {
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_ALL);
}
return self();
}


@Override
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.saveAdditional(tag, registries);

PatchedDataComponentMap.CODEC.encodeStart(NbtOps.INSTANCE, components)
.result()
.ifPresent(componentTag -> tag.put("components", componentTag));
}

@Override
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.loadAdditional(tag, registries);
if (tag.contains("components")) {
DataComponentMap.CODEC.parse(NbtOps.INSTANCE, tag.get("components"))
.result()
.ifPresent(loadedComponents -> {
// 创建新的构建器并合并现有组件
DataComponentMap.Builder builder = DataComponentMap.builder();
// 保留未改变的组件
components.stream().forEach(entry -> {
if (!loadedComponents.has(entry.type())) {
builder.addAll(components);
}
});
// 添加新加载的组件
builder.addAll(loadedComponents);
this.components.setAll(builder.build());
});
}
}

@SuppressWarnings("unchecked")
public T self() {
return (T) this;
}
}
7 changes: 0 additions & 7 deletions src/ww_ag/java/org/polaris2023/ww_ag/events/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,4 @@ public static void rightMilkPlaceAndGet(PlayerInteractEvent.RightClickBlock even
}
}
}

@SubscribeEvent
public static void a(ItemTooltipEvent event) {
ItemStack stack = event.getItemStack();
ResourceLocation location = stack.getOrDefault(ModDataComponents.MILK_TYPE, ModBlocks.MILK.getId());
event.getToolTip().add(Component.literal(location.toString()));
}
}