Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
khjxiaogu committed Sep 15, 2024
1 parent 1f29073 commit 6f3dfe4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos,
private static final Component CONTAINER_TITLE = Component
.translatable("container." + CPMain.MODID + ".tessellation_workbench.title");

public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand,
BlockHitResult pHit) {
if (pLevel.isClientSide) {
return InteractionResult.SUCCESS;
}
pPlayer.openMenu(this.getMenuProvider(pState, pLevel, pPos),pPos);
return InteractionResult.CONSUME;
}

@Nullable
public MenuProvider getMenuProvider(BlockState pState, Level pLevel, BlockPos pPos) {
return new SimpleMenuProvider((p_57074_, p_57075_, p_57076_) -> {
return new TBenchMenu(p_57074_, p_57075_, ContainerLevelAccess.create(pLevel, pPos));
}, CONTAINER_TITLE);
}

@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player,
BlockHitResult hitResult) {
if (level.isClientSide) {
return InteractionResult.SUCCESS;
}
player.openMenu(this.getMenuProvider(state, level, pos),pos);
return InteractionResult.CONSUME;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.teammoeg.caupona.util;

import java.util.NoSuchElementException;
import java.util.function.Function;

import io.netty.buffer.ByteBuf;
Expand All @@ -26,7 +27,8 @@ public static RegistryAccess getRegistryAccess() {
return accessor;
}
public static Function<ByteBuf, RegistryFriendlyByteBuf> getDecorator() {

if(!haveAccess())
throw new NoSuchElementException("no registry access found");
return RegistryFriendlyByteBuf.decorator(accessor, connectionType);
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/teammoeg/caupona/util/SerializeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public static <K, V> Map<K, V> readMap(FriendlyByteBuf buffer, Map<K, V> map, Fu
return map;
}
public static <T> void writeCodec(RegistryFriendlyByteBuf pb, Codec<T> codec, T obj) {
try (CloseableRegistryAccessor i=RegistryAccessor.automated(pb)){
try {
RegistryAccessor.provideRegistryAccess(pb);
if(!CPConfig.COMMON.compressCodecs.get()) {
DataResult<Tag> out=codec.encodeStart(NbtOps.INSTANCE, obj);
Optional<Tag> ret=out.resultOrPartial(CPMain.logger::error);
Expand All @@ -191,10 +192,13 @@ public static <T> void writeCodec(RegistryFriendlyByteBuf pb, Codec<T> codec, T
throw new DecoderException("Can not write Object "+obj+" with Codec "+codec);
}
ObjectWriter.writeObject(pb,ret.get());
}finally {
RegistryAccessor.close();
}
}
public static <T> T readCodec(RegistryFriendlyByteBuf pb, Codec<T> codec) {
try (CloseableRegistryAccessor i=RegistryAccessor.automated(pb)){
try {
RegistryAccessor.provideRegistryAccess(pb);
if(!CPConfig.COMMON.compressCodecs.get()) {
DataResult<Pair<T, Tag>> ob=codec.decode(NbtOps.INSTANCE,pb.readNbt());
Optional<Pair<T, Tag>> ret=ob.resultOrPartial(CPMain.logger::error);
Expand All @@ -207,6 +211,8 @@ public static <T> T readCodec(RegistryFriendlyByteBuf pb, Codec<T> codec) {
throw new DecoderException("Can not read Object "+res+" with Codec "+codec);
}
return ret.get().getFirst();
}finally {
RegistryAccessor.close();
}
}

Expand Down

0 comments on commit 6f3dfe4

Please sign in to comment.