Skip to content

Commit

Permalink
Merge pull request #189 from Gilly7CE/gilly7ce-update-to-1.20.2
Browse files Browse the repository at this point in the history
Update to 1.20.2
  • Loading branch information
Gilly7CE authored Sep 23, 2023
2 parents f87076d + 8bd282c commit f32a9fe
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 288 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 '1.2-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
}

Expand Down
10 changes: 5 additions & 5 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/use
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
# Mod Properties
mod_version=1.3.1
maven_group=carpet-addons-not-found
archives_base_name=carpet-addons-not-found
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
# fabric_version=0.25.1+build.416-1.16
carpet_core_version=1.4.112+v230608
carpet_minecraft_version=1.20
carpet_core_version=1.4.118+v230921
carpet_minecraft_version=1.20.2
18 changes: 0 additions & 18 deletions src/main/java/carpetaddonsnotfound/CarpetAddonsNotFoundServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
import carpet.CarpetServer;
import carpet.api.settings.SettingsManager;
import carpet.utils.Translations;
import carpetaddonsnotfound.network.ServerNetworkHandler;
import carpetaddonsnotfound.ruleobservers.MovableBlockEntitiesRuleObserver;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;

import java.util.Map;

Expand Down Expand Up @@ -50,19 +47,4 @@ public Map<String, String> canHasTranslations(String lang) {
return Translations.getTranslationFromResourcePath(
String.format("assets/carpet-addons-not-found/lang/%s.json", lang));
}

@Override
public void onPlayerLoggedIn(ServerPlayerEntity player) {
ServerNetworkHandler.onPlayerJoin(player);
}

@Override
public void onPlayerLoggedOut(ServerPlayerEntity player) {
ServerNetworkHandler.onPlayerLoggedOut(player);
}

@Override
public void onServerClosed(MinecraftServer server) {
ServerNetworkHandler.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static DispenserBehavior getCustomDispenserBehavior(ServerWorld world,
BlockPointer pointer,
ItemStack itemStack) {
Item item = itemStack.getItem();
Direction dispenserFacing = pointer.getBlockState().get(DispenserBlock.FACING);
Direction dispenserFacing = pointer.state().get(DispenserBlock.FACING);
BlockPos frontBlockPos = pos.offset(dispenserFacing);
BlockState frontBlockState = world.getBlockState(frontBlockPos);
Block frontBlock = frontBlockState.getBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public final class PlaceEyesOfEnderDispenserBehavior extends FallibleItemDispens
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
this.setSuccess(true);
Item item = stack.getItem();
ServerWorld world = pointer.getWorld();
Direction dispenserFacing = pointer.getBlockState().get(DispenserBlock.FACING);
BlockPos frontBlockPos = pointer.getPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
ServerWorld world = pointer.world();
Direction dispenserFacing = pointer.state().get(DispenserBlock.FACING);
BlockPos frontBlockPos = pointer.pos().offset(pointer.state().get(DispenserBlock.FACING));
BlockState frontBlockState = world.getBlockState(frontBlockPos);
Block frontBlock = frontBlockState.getBlock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public final class RemoveEyesOfEnderDispenserBehavior extends FallibleItemDispen
@Override
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
this.setSuccess(true);
ServerWorld world = pointer.getWorld();
BlockPos frontBlockPos = pointer.getPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
ServerWorld world = pointer.world();
BlockPos frontBlockPos = pointer.pos().offset(pointer.state().get(DispenserBlock.FACING));
BlockState frontBlockState = world.getBlockState(frontBlockPos);
Block frontBlock = frontBlockState.getBlock();

Expand Down Expand Up @@ -48,7 +48,7 @@ private ItemStack addEyeOfEnderToInventory(ItemStack originalStack,
return newStack;
}

DispenserBlockEntity dispenserBlockEntity = blockPointer.getBlockEntity();
DispenserBlockEntity dispenserBlockEntity = blockPointer.blockEntity();
return addToFirstAvailableSlot(dispenserBlockEntity, itemToAdd)
? originalStack
: null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package carpetaddonsnotfound.mixins;

import carpetaddonsnotfound.dispenser.CarpetAddonsNotFoundDispenserBehaviors;
import net.minecraft.block.BlockState;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.DispenserBehavior;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPointerImpl;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -45,10 +46,11 @@ public abstract class DispenserBlock_GetCustomBehaviorMixin {
cancellable = true
)
private void dispenseCustomBehaviorNonEmptyItemStack(ServerWorld serverWorld,
BlockState state,
BlockPos pos,
CallbackInfo ci,
BlockPointerImpl blockPointer,
DispenserBlockEntity dispenserBlockEntity,
BlockPointer blockPointer,
int i,
ItemStack itemStack) {
DispenserBehavior customBehavior =
Expand Down Expand Up @@ -93,10 +95,12 @@ private void dispenseCustomBehaviorNonEmptyItemStack(ServerWorld serverWorld,
cancellable = true
)
private void dispenseCustomBehaviorEmptyItemStack(ServerWorld serverWorld,
BlockState state,
BlockPos pos,
CallbackInfo ci,
BlockPointerImpl blockPointer,
DispenserBlockEntity dispenserBlockEntity) {
DispenserBlockEntity dispenserBlockEntity,
BlockPointer blockPointer,
int i) {
ItemStack itemStack = ItemStack.EMPTY;
DispenserBehavior customBehavior =
CarpetAddonsNotFoundDispenserBehaviors.getCustomDispenserBehavior(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import carpetaddonsnotfound.network.CarpetAddonsNotFoundClient;
import carpetaddonsnotfound.network.ClientNetworkHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientCommonNetworkHandler;
import net.minecraft.client.network.ClientConnectionState;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.network.packet.s2c.play.DisconnectS2CPacket;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.packet.CustomPayload;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -19,30 +18,18 @@
* handlers should be placed in the ClientNetworkHandler class.
*/
@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandler_CustomPacketsMixin {
@Final
@Shadow
private MinecraftClient client;
public abstract class ClientPlayNetworkHandler_CustomPacketsMixin extends ClientCommonNetworkHandler {
protected ClientPlayNetworkHandler_CustomPacketsMixin(MinecraftClient minecraft,
ClientConnection connection,
ClientConnectionState commonListenerCookie) {
super(minecraft, connection, commonListenerCookie);
}

@Inject(method = "onCustomPayload", at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/packet/s2c/play" +
"/CustomPayloadS2CPacket;getChannel()" +
"Lnet/minecraft/util/Identifier;"),
cancellable = true)
private void onCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) {
if (CarpetAddonsNotFoundClient.CARPET_ADDONS_NOT_FOUND_CHANNEL.equals(packet.getChannel())) {
ClientNetworkHandler.handleData(packet.getData(), client.player);
@Inject(method = "onCustomPayload", at = @At(value = "HEAD"), cancellable = true)
private void onCustomPayload(CustomPayload packet, CallbackInfo ci) {
if (packet instanceof CarpetAddonsNotFoundClient.CarpetAddonsNotFoundPayload cpp) {
ClientNetworkHandler.handleData(cpp.data(), client.player);
ci.cancel();
}
}

@Inject(method = "onGameJoin", at = @At("RETURN"))
private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {
CarpetAddonsNotFoundClient.gameJoined(client.player);
}

@Inject(method = "onDisconnect", at = @At("HEAD"))
private void onDisconnected(DisconnectS2CPacket packet, CallbackInfo ci) {
CarpetAddonsNotFoundClient.disconnect();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package carpetaddonsnotfound.mixins.network;

import carpetaddonsnotfound.network.CarpetAddonsNotFoundClient;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(CustomPayloadS2CPacket.class)
public abstract class CustomPayloadS2CPacket_CustomPacketMixin {
@Inject(method = "readPayload", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;readUnknownPayload(Lnet/minecraft/util/Identifier;Lnet/minecraft/network/PacketByteBuf;)Lnet/minecraft/network/packet/UnknownCustomPayload;"),
cancellable = true)
private static void onCustomPayload(Identifier resourceLocation, PacketByteBuf friendlyByteBuf, CallbackInfoReturnable<CustomPayload> cir)
{
if (resourceLocation.equals(CarpetAddonsNotFoundClient.CARPET_ADDONS_NOT_FOUND_CHANNEL))
{
cir.setReturnValue(new CarpetAddonsNotFoundClient.CarpetAddonsNotFoundPayload(friendlyByteBuf));
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
package carpetaddonsnotfound.network;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

/**
* Client for the mod. Most of this is taken from CarpetClient
*/
public final class CarpetAddonsNotFoundClient {
public static final int DATA = 1;
public static final int HI = 2;
public static final int HELLO = 3;
public static final Identifier CARPET_ADDONS_NOT_FOUND_CHANNEL = new Identifier("carpet-addons-not-found");

private static ClientPlayerEntity clientPlayer = null;
private static boolean isServerCarpet = false;

public static void gameJoined(ClientPlayerEntity player) {
clientPlayer = player;
}

public static void disconnect() {
if (!isServerCarpet) // multiplayer connection
{
return;
public record CarpetAddonsNotFoundPayload(NbtCompound data) implements CustomPayload {
public CarpetAddonsNotFoundPayload(PacketByteBuf input) {
this(input.readNbt());
}

// singleplayer disconnect
isServerCarpet = false;
clientPlayer = null;
}

public static void setCarpet() {
isServerCarpet = true;
}
@Override
public void write(PacketByteBuf output) {
output.writeNbt(data);
}

public static ClientPlayerEntity getPlayer() {
return clientPlayer;
@Override
public Identifier id() {
return CARPET_ADDONS_NOT_FOUND_CHANNEL;
}
}
}
Loading

0 comments on commit f32a9fe

Please sign in to comment.