Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
before rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
liulihaocai committed Jan 12, 2021
1 parent 4cfc90c commit 5cac7c3
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/liuli/ez4h/InitLibs.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.Date;

public class InitLibs {
public static String VERSION="20210109";
public static String VERSION="0.1";
public static long launchTime=0;
public static void main(String[] args){
launchTime=new Date().getTime();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/liuli/ez4h/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static void initPEProtocol() {
for(Class<? extends BedrockTranslator> translatorClass:subTypes){
try {
BedrockTranslator bedrockTranslator=translatorClass.newInstance();
BedrockTranslatorManager.addTranslator(bedrockTranslator,bedrockTranslator.getPacketClass());
BedrockTranslatorManager.addTranslator(bedrockTranslator);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -133,7 +133,7 @@ private static void initJEProtocol() {
for(Class<? extends JavaTranslator> translatorClass:subTypes){
try {
JavaTranslator javaTranslator=translatorClass.newInstance();
JavaTranslatorManager.addTranslator(javaTranslator,javaTranslator.getPacketClass());
JavaTranslatorManager.addTranslator(javaTranslator);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/liuli/ez4h/mcjava/JavaPacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public void packetReceived(PacketReceivedEvent event) {
Variables.logger.warning("Java > "+packet.toString());
}
if(((MinecraftProtocol) event.getSession().getPacketProtocol()).getSubProtocol() == SubProtocol.STATUS) {
if(event.getPacket() instanceof StatusQueryPacket) {
if(packet instanceof StatusQueryPacket) {
Ping.doPing(event.getSession());
} else if(event.getPacket() instanceof StatusPingPacket) {
} else if(packet instanceof StatusPingPacket) {
event.getSession().send(new StatusPongPacket(event.<StatusPingPacket>getPacket().getPingTime()));
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class BedrockTranslatorManager {
private static Map<Class, BedrockTranslator> packetTranslators = new HashMap<>();
public static void addTranslator(BedrockTranslator translator, Class clazz){
packetTranslators.put(clazz,translator);
public static void addTranslator(BedrockTranslator translator){
packetTranslators.put(translator.getPacketClass(),translator);
}
public static void translatePacket(BedrockPacket packet, Client client){
BedrockTranslator translator=packetTranslators.get(packet.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class JavaTranslatorManager {
private static Map<Class, JavaTranslator> packetTranslators = new HashMap<>();
public static void addTranslator(JavaTranslator translator, Class clazz){
packetTranslators.put(clazz,translator);
public static void addTranslator(JavaTranslator translator){
packetTranslators.put(translator.getPacketClass(),translator);
}
public static void translatePacket(Packet packet, Client client){
JavaTranslator translator=packetTranslators.get(packet.getClass());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package me.liuli.ez4h.translators.bedrockTranslators;

import com.github.steveice10.mc.protocol.data.game.entity.Effect;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEffectPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRemoveEffectPacket;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.packet.MobEffectPacket;
import me.liuli.ez4h.bedrock.Client;
import me.liuli.ez4h.translators.BedrockTranslator;
import me.liuli.ez4h.translators.converters.EffectConverter;

import java.util.ArrayList;
import java.util.List;

public class MobEffectPacketTranslator implements BedrockTranslator {
@Override
public void translate(BedrockPacket inPacket, Client client) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
package me.liuli.ez4h.translators.bedrockTranslators;

import com.github.steveice10.mc.protocol.data.game.world.sound.SoundCategory;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlayBuiltinSoundPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.packet.PlaySoundPacket;
import me.liuli.ez4h.bedrock.Client;
import me.liuli.ez4h.translators.BedrockTranslator;
import me.liuli.ez4h.translators.converters.SoundConverter;

import java.util.Locale;

public class PlaySoundPacketTranslator implements BedrockTranslator {
@Override
public void translate(BedrockPacket inPacket, Client client) {
PlaySoundPacket packet=(PlaySoundPacket)inPacket;
Vector3f pos=packet.getPosition();
SoundCategory category;
try {
category=SoundCategory.valueOf(packet.getSound().split("\\.")[0].toUpperCase());
} catch (Exception e) {
category=SoundCategory.AMBIENT;
}
client.sendPacket(new ServerPlayBuiltinSoundPacket(SoundConverter.convert(packet.getSound()), category, pos.getX(), pos.getY(), pos.getZ(), packet.getVolume(), packet.getPitch()));
//TODO:REWRITE
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static void load(JSONArray blockArray,JSONObject blockRuntimeData){
}
}
}
//TODO:Make this faster
//Process time TOO LONG :(
public static void addLight(NibbleArray3d lightArray,int light,int X,int Y,int Z){
int posX=Math.max((X - light), 0),posXend=Math.min(X + light, 15),
Expand Down
Loading

0 comments on commit 5cac7c3

Please sign in to comment.