Skip to content

Commit

Permalink
connection state, bee, more
Browse files Browse the repository at this point in the history
  • Loading branch information
pisaiah committed May 4, 2024
1 parent 4000731 commit 271e048
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 1 deletion.
15 changes: 15 additions & 0 deletions iCommon-API/src/main/java/me/isaiah/common/ConnectionState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.isaiah.common;

// HandshakeC2SPacket

public class ConnectionState {

public static int HANDSHAKING = -1;
public static int PLAY = 0;
public static int STATUS = 1;
public static int LOGIN = 2;

public static int CONFIGURATION = 3;
public static int TRANSFER = 4;

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package me.isaiah.common.cmixin;

import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;

public interface IMixinBlockEntity {

public NbtCompound I_createNbtWithIdentifyingData();

/**
*/
public void IC$add_bee_to_beehive(ServerWorld world, int rand);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.CommandManager.RegistrationEnvironment;
Expand Down Expand Up @@ -72,4 +73,8 @@ public interface IMixinMinecraftServer {
*/
public String IC$to_json(Text text);

/**
*/
public int IC$get_connection_state(HandshakeC2SPacket packet);

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import me.isaiah.common.event.EventRegistery;
import me.isaiah.common.event.block.BlockEntityWriteNbtEvent;
import me.isaiah.common.event.entity.BlockEntityLoadEvent;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;

@Mixin(BlockEntity.class)
public class MixinBlockEntity implements IMixinBlockEntity {
Expand All @@ -32,4 +36,14 @@ public NbtCompound I_createNbtWithIdentifyingData() {
return ((BlockEntity)(Object)this).createNbtWithIdentifyingData();
}

@Override
public void IC$add_bee_to_beehive(ServerWorld world, int rand) {
BlockEntity tileentity = (BlockEntity) (Object) this;
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehive = (BeehiveBlockEntity) tileentity;
BeeEntity bee = new BeeEntity(EntityType.BEE, world);
beehive.tryEnterHive(bee, false, rand);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import com.mojang.authlib.GameProfile;
import com.mojang.serialization.DynamicOps;

import me.isaiah.common.ConnectionState;
import me.isaiah.common.ICommonMod;
import me.isaiah.common.cmixin.IMixinMinecraftServer;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetworkState;
import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.resource.ResourceManager;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -87,5 +90,23 @@ public EntityStatusEffectS2CPacket new_status_effect_packet(int id, StatusEffect
public String IC$to_json(Text text) {
return Text.Serializer.toJson(text);
}

@Override
public int IC$get_connection_state(HandshakeC2SPacket packet) {
NetworkState state = packet.getIntendedState();
switch (state) {
case HANDSHAKING:
return ConnectionState.HANDSHAKING;
case LOGIN:
return ConnectionState.LOGIN;
case PLAY:
return ConnectionState.PLAY;
case STATUS:
return ConnectionState.STATUS;
default:
break;
}
return -2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import me.isaiah.common.event.EventRegistery;
import me.isaiah.common.event.block.BlockEntityWriteNbtEvent;
import me.isaiah.common.event.entity.BlockEntityLoadEvent;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;

@Mixin(BlockEntity.class)
public class MixinBlockEntity implements IMixinBlockEntity {
Expand All @@ -31,5 +35,15 @@ public void saveEnd(NbtCompound tag, CallbackInfo callback) {
public NbtCompound I_createNbtWithIdentifyingData() {
return ((BlockEntity)(Object)this).createNbtWithIdentifyingData();
}

@Override
public void IC$add_bee_to_beehive(ServerWorld world, int rand) {
BlockEntity tileentity = (BlockEntity) (Object) this;
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehive = (BeehiveBlockEntity) tileentity;
BeeEntity bee = new BeeEntity(EntityType.BEE, world);
beehive.tryEnterHive(bee, false, rand);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import org.spongepowered.asm.mixin.Mixin;

import com.mojang.authlib.GameProfile;

import me.isaiah.common.ConnectionState;
import me.isaiah.common.ICommonMod;
import me.isaiah.common.cmixin.IMixinMinecraftServer;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetworkState;
import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.registry.DynamicRegistryManager;
Expand Down Expand Up @@ -126,5 +130,23 @@ public EntityStatusEffectS2CPacket new_status_effect_packet(int id, StatusEffect
public String IC$to_json(Text text) {
return Text.Serializer.toJson(text);
}

@Override
public int IC$get_connection_state(HandshakeC2SPacket packet) {
NetworkState state = packet.getIntendedState();
switch (state) {
case HANDSHAKING:
return ConnectionState.HANDSHAKING;
case LOGIN:
return ConnectionState.LOGIN;
case PLAY:
return ConnectionState.PLAY;
case STATUS:
return ConnectionState.STATUS;
default:
break;
}
return -2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import me.isaiah.common.event.EventRegistery;
import me.isaiah.common.event.block.BlockEntityWriteNbtEvent;
import me.isaiah.common.event.entity.BlockEntityLoadEvent;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;

@Mixin(BlockEntity.class)
public class MixinBlockEntity implements IMixinBlockEntity {
Expand All @@ -31,5 +35,15 @@ public void saveEnd(NbtCompound tag, CallbackInfo callback) {
public NbtCompound I_createNbtWithIdentifyingData() {
return ((BlockEntity)(Object)this).createNbtWithIdentifyingData();
}

@Override
public void IC$add_bee_to_beehive(ServerWorld world, int rand) {
BlockEntity tileentity = (BlockEntity) (Object) this;
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehive = (BeehiveBlockEntity) tileentity;
BeeEntity bee = new BeeEntity(EntityType.BEE, world);
beehive.tryEnterHive(bee, false, rand);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import com.mojang.authlib.GameProfile;
import com.mojang.serialization.DynamicOps;

import me.isaiah.common.ConnectionState;
import me.isaiah.common.ICommonMod;
import me.isaiah.common.cmixin.IMixinMinecraftServer;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetworkState;
import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.resource.ResourceManager;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -125,5 +128,23 @@ public EntityStatusEffectS2CPacket new_status_effect_packet(int id, StatusEffect
public String IC$to_json(Text text) {
return Text.Serializer.toJson(text);
}

@Override
public int IC$get_connection_state(HandshakeC2SPacket packet) {
NetworkState state = packet.getIntendedState();
switch (state) {
case HANDSHAKING:
return ConnectionState.HANDSHAKING;
case LOGIN:
return ConnectionState.LOGIN;
case PLAY:
return ConnectionState.PLAY;
case STATUS:
return ConnectionState.STATUS;
default:
break;
}
return -2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import me.isaiah.common.event.EventRegistery;
import me.isaiah.common.event.block.BlockEntityWriteNbtEvent;
import me.isaiah.common.event.entity.BlockEntityLoadEvent;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;

@Mixin(BlockEntity.class)
public class MixinBlockEntity implements IMixinBlockEntity {
Expand All @@ -31,5 +35,15 @@ public void saveEnd(NbtCompound tag, CallbackInfo callback) {
public NbtCompound I_createNbtWithIdentifyingData() {
return ((BlockEntity)(Object)this).createNbtWithIdentifyingData();
}

@Override
public void IC$add_bee_to_beehive(ServerWorld world, int rand) {
BlockEntity tileentity = (BlockEntity) (Object) this;
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehive = (BeehiveBlockEntity) tileentity;
BeeEntity bee = new BeeEntity(EntityType.BEE, world);
beehive.tryEnterHive(bee, false, rand);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import org.spongepowered.asm.mixin.Mixin;

import com.mojang.authlib.GameProfile;

import me.isaiah.common.ConnectionState;
import me.isaiah.common.ICommonMod;
import me.isaiah.common.cmixin.IMixinMinecraftServer;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.item.ItemStack;
import net.minecraft.network.NetworkState;
import net.minecraft.network.packet.c2s.handshake.HandshakeC2SPacket;
import net.minecraft.network.packet.s2c.play.EntityStatusEffectS2CPacket;
import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.registry.DynamicRegistryManager;
Expand Down Expand Up @@ -127,4 +131,22 @@ public EntityStatusEffectS2CPacket new_status_effect_packet(int id, StatusEffect
return Text.Serializer.toJson(text);
}

@Override
public int IC$get_connection_state(HandshakeC2SPacket packet) {
NetworkState state = packet.getIntendedState();
switch (state) {
case HANDSHAKING:
return ConnectionState.HANDSHAKING;
case LOGIN:
return ConnectionState.LOGIN;
case PLAY:
return ConnectionState.PLAY;
case STATUS:
return ConnectionState.STATUS;
default:
break;
}
return -2;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import me.isaiah.common.event.EventRegistery;
import me.isaiah.common.event.block.BlockEntityWriteNbtEvent;
import me.isaiah.common.event.entity.BlockEntityLoadEvent;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;

@Mixin(BlockEntity.class)
public class MixinBlockEntity implements IMixinBlockEntity {
Expand All @@ -31,5 +35,15 @@ public void saveEnd(NbtCompound tag, CallbackInfo callback) {
public NbtCompound I_createNbtWithIdentifyingData() {
return ((BlockEntity)(Object)this).createNbtWithIdentifyingData();
}

@Override
public void IC$add_bee_to_beehive(ServerWorld world, int rand) {
BlockEntity tileentity = (BlockEntity) (Object) this;
if (tileentity instanceof BeehiveBlockEntity) {
BeehiveBlockEntity beehive = (BeehiveBlockEntity) tileentity;
BeeEntity bee = new BeeEntity(EntityType.BEE, world);
beehive.tryEnterHive(bee, false, rand);
}
}

}
Loading

0 comments on commit 271e048

Please sign in to comment.