mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-11 07:08:17 +02:00
Fix mob NPCs and get closer to working players (not yet though)
This commit is contained in:
parent
15b1bd0683
commit
3c9b42355f
80
src/main/java/net/citizensnpcs/npc/network/EmptyChannel.java
Normal file
80
src/main/java/net/citizensnpcs/npc/network/EmptyChannel.java
Normal file
@ -0,0 +1,80 @@
|
||||
package net.citizensnpcs.npc.network;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import net.minecraft.util.io.netty.channel.AbstractChannel;
|
||||
import net.minecraft.util.io.netty.channel.Channel;
|
||||
import net.minecraft.util.io.netty.channel.ChannelConfig;
|
||||
import net.minecraft.util.io.netty.channel.ChannelMetadata;
|
||||
import net.minecraft.util.io.netty.channel.ChannelOutboundBuffer;
|
||||
import net.minecraft.util.io.netty.channel.DefaultChannelConfig;
|
||||
import net.minecraft.util.io.netty.channel.EventLoop;
|
||||
|
||||
public class EmptyChannel extends AbstractChannel {
|
||||
private final ChannelConfig config = new DefaultChannelConfig(this);
|
||||
|
||||
public EmptyChannel(Channel parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelConfig config() {
|
||||
config.setAutoRead(true);
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBeginRead() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(SocketAddress arg0) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doDisconnect() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doWrite(ChannelOutboundBuffer arg0) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCompatible(EventLoop arg0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress localAddress0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelMetadata metadata() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractUnsafe newUnsafe() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SocketAddress remoteAddress0() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -2,17 +2,12 @@ package net.citizensnpcs.npc.network;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.minecraft.server.v1_7_R1.NetworkManager;
|
||||
import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
public class EmptyNetworkManager extends NetworkManager {
|
||||
public EmptyNetworkManager(boolean flag) throws IOException {
|
||||
super(flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
ctx.channel().close();
|
||||
NMS.initNetworkManager(this);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package net.citizensnpcs.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -12,6 +13,7 @@ import java.util.WeakHashMap;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.npc.entity.EntityHumanNPC;
|
||||
import net.citizensnpcs.npc.network.EmptyChannel;
|
||||
import net.minecraft.server.v1_7_R1.AttributeInstance;
|
||||
import net.minecraft.server.v1_7_R1.ControllerJump;
|
||||
import net.minecraft.server.v1_7_R1.DamageSource;
|
||||
@ -27,6 +29,7 @@ import net.minecraft.server.v1_7_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_7_R1.MathHelper;
|
||||
import net.minecraft.server.v1_7_R1.MobEffectList;
|
||||
import net.minecraft.server.v1_7_R1.Navigation;
|
||||
import net.minecraft.server.v1_7_R1.NetworkManager;
|
||||
import net.minecraft.server.v1_7_R1.Packet;
|
||||
import net.minecraft.server.v1_7_R1.PathfinderGoalSelector;
|
||||
import net.minecraft.server.v1_7_R1.World;
|
||||
@ -218,6 +221,21 @@ public class NMS {
|
||||
return DEFAULT_SPEED;
|
||||
}
|
||||
|
||||
public static void initNetworkManager(NetworkManager network) {
|
||||
if (NETWORK_CHANNEL == null || NETWORK_ADDRESS == null)
|
||||
return;
|
||||
try {
|
||||
NETWORK_CHANNEL.set(network, new EmptyChannel(null));
|
||||
NETWORK_ADDRESS.set(network, new SocketAddress() {
|
||||
private static final long serialVersionUID = 8207338859896320185L;
|
||||
});
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inWater(org.bukkit.entity.Entity entity) {
|
||||
Entity mcEntity = getHandle(entity);
|
||||
return mcEntity.M() || mcEntity.P();
|
||||
@ -484,16 +502,19 @@ public class NMS {
|
||||
private static Map<Class<?>, Integer> MC_ENTITY_CLASS_TO_INT = null;
|
||||
private static Map<Integer, Class<?>> MC_ENTITY_INT_TO_CLASS = null;
|
||||
private static Field NAVIGATION_WORLD_FIELD = getField(Navigation.class, "b");
|
||||
private static Field NETWORK_ADDRESS = getField(NetworkManager.class, "l");
|
||||
private static Field NETWORK_CHANNEL = getField(NetworkManager.class, "k");
|
||||
private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static Field PATHFINDING_RANGE = getField(Navigation.class, "e");
|
||||
|
||||
private static final Random RANDOM = Util.getFastRandom();
|
||||
// true field above false and three synchronised lists
|
||||
|
||||
static {
|
||||
try {
|
||||
Field field = getField(EntityTypes.class, "d");
|
||||
Field field = getField(EntityTypes.class, "e");
|
||||
ENTITY_INT_TO_CLASS = (Map<Integer, Class<?>>) field.get(null);
|
||||
field = getField(EntityTypes.class, "e");
|
||||
field = getField(EntityTypes.class, "f");
|
||||
ENTITY_CLASS_TO_INT = (Map<Class<?>, Integer>) field.get(null);
|
||||
} catch (Exception e) {
|
||||
Messaging.logTr(Messages.ERROR_GETTING_ID_MAPPING, e.getMessage());
|
||||
|
Loading…
Reference in New Issue
Block a user