mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-24 22:14:42 +00:00
Zappidy zoom time!
This commit is contained in:
1 parent
6fa96d9376
commit
822ebff789
7 files changed
+405
-279
No files matched your search
@@ -1,5 +1,22 @@
|
||||
package crazypants.enderio.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageCodec;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler;
|
||||
@@ -7,207 +24,221 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageCodec;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.INetHandler;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
|
||||
import java.util.*;
|
||||
/**
|
||||
* Packet pipeline class. Directs all registered packet data to be handled by
|
||||
* the packets themselves.
|
||||
*
|
||||
* @author sirgingalot some code from: cpw
|
||||
*/
|
||||
@ChannelHandler.Sharable
|
||||
public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, IPacketEio> {
|
||||
|
||||
private EnumMap<Side, FMLEmbeddedChannel> channels;
|
||||
private LinkedList<Class<? extends IPacketEio>> packets = new LinkedList<Class<? extends IPacketEio>>();
|
||||
private boolean isPostInitialised = false;
|
||||
|
||||
/**
|
||||
* Packet pipeline class. Directs all registered packet data to be handled by the packets themselves.
|
||||
* @author sirgingalot
|
||||
* some code from: cpw
|
||||
* Register your packet with the pipeline. Discriminators are automatically
|
||||
* set.
|
||||
*
|
||||
* @param clazz
|
||||
* the class to register
|
||||
*
|
||||
* @return whether registration was successful. Failure may occur if 256
|
||||
* packets have been registered or if the registry already contains
|
||||
* this packet
|
||||
*/
|
||||
@ChannelHandler.Sharable
|
||||
public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, IPacketEio> {
|
||||
|
||||
private EnumMap<Side, FMLEmbeddedChannel> channels;
|
||||
private LinkedList<Class<? extends IPacketEio>> packets = new LinkedList<Class<? extends IPacketEio>>();
|
||||
private boolean isPostInitialised = false;
|
||||
|
||||
/**
|
||||
* Register your packet with the pipeline. Discriminators are automatically set.
|
||||
*
|
||||
* @param clazz the class to register
|
||||
*
|
||||
* @return whether registration was successful. Failure may occur if 256 packets have been registered or if the registry already contains this packet
|
||||
*/
|
||||
public boolean registerPacket(Class<? extends IPacketEio> clazz) {
|
||||
if (this.packets.size() > 256) {
|
||||
// You should log here!!
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.packets.contains(clazz)) {
|
||||
// You should log here!!
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isPostInitialised) {
|
||||
// You should log here!!
|
||||
return false;
|
||||
}
|
||||
|
||||
this.packets.add(clazz);
|
||||
return true;
|
||||
public boolean registerPacket(Class<? extends IPacketEio> clazz) {
|
||||
if(this.packets.size() > 256) {
|
||||
// You should log here!!
|
||||
return false;
|
||||
}
|
||||
|
||||
// In line encoding of the packet, including discriminator setting
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, IPacketEio msg, List<Object> out) throws Exception {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
Class<? extends IPacketEio> clazz = msg.getClass();
|
||||
if (!this.packets.contains(msg.getClass())) {
|
||||
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
byte discriminator = (byte) this.packets.indexOf(clazz);
|
||||
buffer.writeByte(discriminator);
|
||||
msg.encode(ctx, buffer);
|
||||
FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
|
||||
out.add(proxyPacket);
|
||||
if(this.packets.contains(clazz)) {
|
||||
// You should log here!!
|
||||
return false;
|
||||
}
|
||||
|
||||
// In line decoding and handling of the packet
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
|
||||
ByteBuf payload = msg.payload();
|
||||
byte discriminator = payload.readByte();
|
||||
Class<? extends IPacketEio> clazz = this.packets.get(discriminator);
|
||||
if (clazz == null) {
|
||||
throw new NullPointerException("No packet registered for discriminator: " + discriminator);
|
||||
}
|
||||
|
||||
IPacketEio pkt = clazz.newInstance();
|
||||
pkt.decode(ctx, payload.slice());
|
||||
|
||||
EntityPlayer player;
|
||||
switch (FMLCommonHandler.instance().getEffectiveSide()) {
|
||||
case CLIENT:
|
||||
player = this.getClientPlayer();
|
||||
pkt.handleClientSide(player);
|
||||
break;
|
||||
|
||||
case SERVER:
|
||||
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
|
||||
player = ((NetHandlerPlayServer) netHandler).playerEntity;
|
||||
pkt.handleServerSide(player);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
out.add(pkt);
|
||||
if(this.isPostInitialised) {
|
||||
// You should log here!!
|
||||
return false;
|
||||
}
|
||||
|
||||
// Method to call from FMLInitializationEvent
|
||||
public void initalise() {
|
||||
this.channels = NetworkRegistry.INSTANCE.newChannel("TConstruct", this);
|
||||
registerPackets();
|
||||
this.packets.add(clazz);
|
||||
return true;
|
||||
}
|
||||
|
||||
// In line encoding of the packet, including discriminator setting
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, IPacketEio msg, List<Object> out) throws Exception {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
Class<? extends IPacketEio> clazz = msg.getClass();
|
||||
if(!this.packets.contains(msg.getClass())) {
|
||||
throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
|
||||
}
|
||||
|
||||
public void registerPackets(){
|
||||
byte discriminator = (byte) this.packets.indexOf(clazz);
|
||||
buffer.writeByte(discriminator);
|
||||
msg.encode(ctx, buffer);
|
||||
FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
|
||||
out.add(proxyPacket);
|
||||
}
|
||||
|
||||
// In line decoding and handling of the packet
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
|
||||
ByteBuf payload = msg.payload();
|
||||
byte discriminator = payload.readByte();
|
||||
Class<? extends IPacketEio> clazz = this.packets.get(discriminator);
|
||||
if(clazz == null) {
|
||||
throw new NullPointerException("No packet registered for discriminator: " + discriminator);
|
||||
}
|
||||
|
||||
// Method to call from FMLPostInitializationEvent
|
||||
// Ensures that packet discriminators are common between server and client by using logical sorting
|
||||
public void postInitialise() {
|
||||
if (this.isPostInitialised) {
|
||||
return;
|
||||
}
|
||||
IPacketEio pkt = clazz.newInstance();
|
||||
pkt.decode(ctx, payload.slice());
|
||||
|
||||
this.isPostInitialised = true;
|
||||
Collections.sort(this.packets, new Comparator<Class<? extends IPacketEio>>() {
|
||||
EntityPlayer player;
|
||||
switch (FMLCommonHandler.instance().getEffectiveSide()) {
|
||||
case CLIENT:
|
||||
player = this.getClientPlayer();
|
||||
pkt.handleClientSide(player);
|
||||
break;
|
||||
|
||||
@Override
|
||||
public int compare(Class<? extends IPacketEio> clazz1, Class<? extends IPacketEio> clazz2) {
|
||||
int com = String.CASE_INSENSITIVE_ORDER.compare(clazz1.getCanonicalName(), clazz2.getCanonicalName());
|
||||
if(com == 0) {
|
||||
com = clazz1.getCanonicalName().compareTo(clazz2.getCanonicalName());
|
||||
}
|
||||
case SERVER:
|
||||
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
|
||||
player = ((NetHandlerPlayServer) netHandler).playerEntity;
|
||||
pkt.handleServerSide(player);
|
||||
break;
|
||||
|
||||
return com;
|
||||
default:
|
||||
}
|
||||
|
||||
out.add(pkt);
|
||||
}
|
||||
|
||||
// Method to call from FMLInitializationEvent
|
||||
public void initalise() {
|
||||
this.channels = NetworkRegistry.INSTANCE.newChannel("TConstruct", this);
|
||||
registerPackets();
|
||||
}
|
||||
|
||||
public void registerPackets() {
|
||||
|
||||
}
|
||||
|
||||
// Method to call from FMLPostInitializationEvent
|
||||
// Ensures that packet discriminators are common between server and client by using logical sorting
|
||||
public void postInitialise() {
|
||||
if(this.isPostInitialised) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isPostInitialised = true;
|
||||
Collections.sort(this.packets, new Comparator<Class<? extends IPacketEio>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Class<? extends IPacketEio> clazz1, Class<? extends IPacketEio> clazz2) {
|
||||
int com = String.CASE_INSENSITIVE_ORDER.compare(clazz1.getCanonicalName(), clazz2.getCanonicalName());
|
||||
if(com == 0) {
|
||||
com = clazz1.getCanonicalName().compareTo(clazz2.getCanonicalName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private EntityPlayer getClientPlayer() {
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
}
|
||||
return com;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message The message to send
|
||||
*/
|
||||
public void sendToAll(IPacketEio message) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
private EntityPlayer getClientPlayer() {
|
||||
return Minecraft.getMinecraft().thePlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to the specified player.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message The message to send
|
||||
* @param player The player to send it to
|
||||
*/
|
||||
public void sendTo(IPacketEio message, EntityPlayerMP player) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
/**
|
||||
* Send this message to everyone.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
*/
|
||||
public void sendToAll(IPacketEio message) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone within a certain range of a point.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message The message to send
|
||||
* @param point The {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint} around which to send
|
||||
*/
|
||||
public void sendToAllAround(IPacketEio message, NetworkRegistry.TargetPoint point) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
/**
|
||||
* Send this message to the specified player.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param player
|
||||
* The player to send it to
|
||||
*/
|
||||
public void sendTo(IPacketEio message, EntityPlayerMP player) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone within the supplied dimension.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message The message to send
|
||||
* @param dimensionId The dimension id to target
|
||||
*/
|
||||
public void sendToDimension(IPacketEio message, int dimensionId) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
public void sendTo(Object message, EntityPlayerMP player) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to the server.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message The message to send
|
||||
*/
|
||||
public void sendToServer(IPacketEio message) {
|
||||
this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER);
|
||||
this.channels.get(Side.CLIENT).writeAndFlush(message);
|
||||
}
|
||||
/**
|
||||
* Send this message to everyone within a certain range of a point.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param point
|
||||
* The
|
||||
* {@link cpw.mods.fml.common.network.NetworkRegistry.TargetPoint}
|
||||
* around which to send
|
||||
*/
|
||||
public void sendToAllAround(IPacketEio message, NetworkRegistry.TargetPoint point) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(point);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone within the supplied dimension.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
* @param dimensionId
|
||||
* The dimension id to target
|
||||
*/
|
||||
public void sendToDimension(IPacketEio message, int dimensionId) {
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.DIMENSION);
|
||||
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
|
||||
this.channels.get(Side.SERVER).writeAndFlush(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to the server.
|
||||
* <p/>
|
||||
* Adapted from CPW's code in
|
||||
* cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper
|
||||
*
|
||||
* @param message
|
||||
* The message to send
|
||||
*/
|
||||
public void sendToServer(IPacketEio message) {
|
||||
this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER);
|
||||
this.channels.get(Side.CLIENT).writeAndFlush(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package crazypants.enderio.teleport;
|
||||
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.*;
|
||||
import crazypants.util.Lang;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -15,8 +11,16 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.enderio.Config;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class BlockTravelAnchor extends Block implements IGuiHandler, ITileEntityProvider {
|
||||
public class BlockTravelAnchor extends Block implements IGuiHandler, ITileEntityProvider {
|
||||
|
||||
public static BlockTravelAnchor create() {
|
||||
|
||||
@@ -28,6 +32,8 @@ public class BlockTravelAnchor extends Block implements IGuiHandler, ITileEntity
|
||||
//FMLCommonHandler.instance().bus().register(new TClientTickHandler());
|
||||
|
||||
EnderIO.packetPipeline.registerPacket(PacketAccessMode.class);
|
||||
EnderIO.packetPipeline.registerPacket(PacketTravelEvent.class);
|
||||
|
||||
BlockTravelAnchor result = new BlockTravelAnchor();
|
||||
result.init();
|
||||
return result;
|
||||
@@ -73,7 +79,7 @@ public class BlockTravelAnchor extends Block implements IGuiHandler, ITileEntity
|
||||
if(entity instanceof EntityPlayer) {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
((TileTravelAnchor) te).setPlacedBy((EntityPlayer)entity);
|
||||
((TileTravelAnchor) te).setPlacedBy((EntityPlayer) entity);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package crazypants.enderio.teleport;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cofh.api.energy.ItemEnergyContainer;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
@@ -15,13 +22,6 @@ import crazypants.enderio.ModObject;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyContainerItem {
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyConta
|
||||
|
||||
Vector3d sample = new Vector3d();
|
||||
|
||||
for (int i = (int) Math.round(Config.travelStaffMaxBlinkDistance); i > 0; i--) {
|
||||
for (int i = Math.round(Config.travelStaffMaxBlinkDistance); i > 0; i--) {
|
||||
sample.set(look);
|
||||
sample.scale(i);
|
||||
sample.add(eye);
|
||||
@@ -88,7 +88,6 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyConta
|
||||
return equipped;
|
||||
}
|
||||
|
||||
|
||||
if(world.isRemote) {
|
||||
if(TravelController.instance.hasTarget()) {
|
||||
BlockCoord target = TravelController.instance.selectedCoord;
|
||||
@@ -96,8 +95,8 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyConta
|
||||
if(te instanceof ITravelAccessable) {
|
||||
ITravelAccessable ta = (ITravelAccessable) te;
|
||||
if(ta.getRequiresPassword(player)) {
|
||||
// Packet packet = TravelPacketHandler.createOpenAuthGuiPacket(target.x, target.y, target.z);
|
||||
// PacketDispatcher.sendPacketToServer(packet);
|
||||
// Packet packet = TravelPacketHandler.createOpenAuthGuiPacket(target.x, target.y, target.z);
|
||||
// PacketDispatcher.sendPacketToServer(packet);
|
||||
return equipped;
|
||||
}
|
||||
}
|
||||
@@ -119,9 +118,9 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyConta
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) {
|
||||
super.addInformation(itemStack, par2EntityPlayer, list, par4);
|
||||
//TODO:1.7
|
||||
// String str = PowerDisplayUtil.formatPower(getEnergyStored(itemStack)) + "/"
|
||||
// + PowerDisplayUtil.formatPower(getMaxEnergyStored(itemStack)) + " " + PowerDisplayUtil.abrevation();
|
||||
// list.add(str);
|
||||
// String str = PowerDisplayUtil.formatPower(getEnergyStored(itemStack)) + "/"
|
||||
// + PowerDisplayUtil.formatPower(getMaxEnergyStored(itemStack)) + " " + PowerDisplayUtil.abrevation();
|
||||
// list.add(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,10 +164,9 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyConta
|
||||
stack.setItemDamage(res);
|
||||
}
|
||||
|
||||
//TODO:1.7
|
||||
//@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List) {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List par3List) {
|
||||
ItemStack is = new ItemStack(this);
|
||||
setFull(is);
|
||||
par3List.add(is);
|
||||
@@ -176,7 +174,6 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IEnergyConta
|
||||
is = new ItemStack(this);
|
||||
setEnergy(is, 0);
|
||||
par3List.add(is);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,8 +52,7 @@ public class PacketAccessMode implements IPacketEio {
|
||||
if(te instanceof TileTravelAnchor) {
|
||||
((TileTravelAnchor) te).setAccessMode(mode);
|
||||
player.worldObj.markBlockForUpdate(x, y, z);
|
||||
player.worldObj.markTileEntityChunkModified(x,y,z,te);
|
||||
System.out.println("crazypants.enderio.teleport.PacketAccessMode.handleServerSide");
|
||||
player.worldObj.markTileEntityChunkModified(x,y,z,te);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package crazypants.enderio.teleport;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.play.server.S12PacketEntityVelocity;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.IPacketEio;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class PacketTravelEvent implements IPacketEio {
|
||||
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int powerUse;
|
||||
boolean conserveMotion;
|
||||
|
||||
public PacketTravelEvent() {
|
||||
}
|
||||
|
||||
public PacketTravelEvent(int x, int y, int z, int powerUse, boolean conserveMotion) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.powerUse = powerUse;
|
||||
this.conserveMotion = conserveMotion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
buffer.writeInt(powerUse);
|
||||
buffer.writeBoolean(conserveMotion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
x = buffer.readInt();
|
||||
y = buffer.readInt();
|
||||
z = buffer.readInt();
|
||||
powerUse = buffer.readInt();
|
||||
conserveMotion = buffer.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer ep) {
|
||||
|
||||
ep.worldObj.playSoundEffect(ep.posX, ep.posY, ep.posZ, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
|
||||
ep.playSound("mob.endermen.portal", 1.0F, 1.0F);
|
||||
|
||||
ep.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
|
||||
|
||||
ep.worldObj.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
ep.fallDistance = 0;
|
||||
|
||||
if(conserveMotion) {
|
||||
Vector3d velocityVex = Util.getLookVecEio(ep);
|
||||
S12PacketEntityVelocity p = new S12PacketEntityVelocity(ep.getEntityId(), velocityVex.x, velocityVex.y, velocityVex.z);
|
||||
|
||||
EnderIO.packetPipeline.sendTo(p, (EntityPlayerMP) ep);
|
||||
|
||||
}
|
||||
|
||||
if(powerUse > 0 && ep.getCurrentEquippedItem() != null && ep.getCurrentEquippedItem().getItem() == EnderIO.itemTravelStaff) {
|
||||
ItemStack item = ep.getCurrentEquippedItem().copy();
|
||||
EnderIO.itemTravelStaff.extractInternal(item, powerUse);
|
||||
ep.setCurrentItemOrArmor(0, item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,23 @@
|
||||
package crazypants.enderio.teleport;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovementInput;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -11,20 +28,12 @@ import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.enderface.TileEnderIO;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.*;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import crazypants.vecmath.Camera;
|
||||
import crazypants.vecmath.Matrix4d;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
import crazypants.vecmath.Vector2d;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
import crazypants.vecmath.Vector4d;
|
||||
|
||||
public class TravelController {
|
||||
|
||||
@@ -48,12 +57,10 @@ public class TravelController {
|
||||
|
||||
private double fovRad;
|
||||
|
||||
|
||||
private double tanFovRad;
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
|
||||
private TravelController() {
|
||||
}
|
||||
|
||||
@@ -92,26 +99,24 @@ public class TravelController {
|
||||
return EnderIO.instance.proxy.getClientPlayer().worldObj.getBlock(selectedCoord.x, selectedCoord.y, selectedCoord.z) == EnderIO.blockEnderIo;
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRender(RenderWorldLastEvent event) {
|
||||
|
||||
|
||||
Vector3d eye = Util.getEyePositionEio(mc.thePlayer);
|
||||
Vector3d lookAt = Util.getLookVecEio(mc.thePlayer);
|
||||
lookAt.add(eye);
|
||||
Matrix4d mv = VecmathUtil.createMatrixAsLookAt(eye, lookAt, new Vector3d(0, 1, 0));
|
||||
|
||||
float fov = 70 + Minecraft.getMinecraft().gameSettings.fovSetting * 40.0F;
|
||||
Matrix4d pr = VecmathUtil.createProjectionMatrixAsPerspective(fov, 0.05f, (float) (mc.gameSettings.renderDistanceChunks * 16), mc.displayWidth,
|
||||
Matrix4d pr = VecmathUtil.createProjectionMatrixAsPerspective(fov, 0.05f, mc.gameSettings.renderDistanceChunks * 16, mc.displayWidth,
|
||||
mc.displayHeight);
|
||||
currentView.setProjectionMatrix(pr);
|
||||
currentView.setViewMatrix(mv);
|
||||
currentView.setViewport(0, 0, mc.displayWidth, mc.displayHeight);
|
||||
|
||||
|
||||
fovRad = Math.toRadians(fov) / 2;
|
||||
tanFovRad = Math.tanh(fovRad);
|
||||
}
|
||||
fovRad = Math.toRadians(fov) / 2;
|
||||
tanFovRad = Math.tanh(fovRad);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
@@ -138,8 +143,8 @@ public class TravelController {
|
||||
ITravelAccessable ta = (ITravelAccessable) te;
|
||||
if(ta.getRequiresPassword(player)) {
|
||||
//TODO:1.7
|
||||
// Packet packet = TravelPacketHandler.createOpenAuthGuiPacket(target.x, target.y, target.z);
|
||||
// PacketDispatcher.sendPacketToServer(packet);
|
||||
// Packet packet = TravelPacketHandler.createOpenAuthGuiPacket(target.x, target.y, target.z);
|
||||
// PacketDispatcher.sendPacketToServer(packet);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -173,7 +178,7 @@ public class TravelController {
|
||||
if(requiredPower <= 0 || requiredPower <= EnderIO.itemTravelStaff.getEnergyStored(equipped)) {
|
||||
if(requiredPower > 0) {
|
||||
//TODO:1.7
|
||||
// PacketDispatcher.sendPacketToServer(TravelPacketHandler.createDrainPowerPacket(requiredPower));
|
||||
// PacketDispatcher.sendPacketToServer(TravelPacketHandler.createDrainPowerPacket(requiredPower));
|
||||
}
|
||||
player.openGui(EnderIO.instance, GuiHandler.GUI_ID_ENDERFACE, world, target.x,
|
||||
TravelController.instance.selectedCoord.y, TravelController.instance.selectedCoord.z);
|
||||
@@ -221,7 +226,7 @@ public class TravelController {
|
||||
}
|
||||
sendTravelEvent(coord, source, requiredPower);
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
player.worldObj.spawnParticle("portal", player.posX + (rand.nextDouble() - 0.5D), player.posY + rand.nextDouble() * (double) player.height - 0.25D,
|
||||
player.worldObj.spawnParticle("portal", player.posX + (rand.nextDouble() - 0.5D), player.posY + rand.nextDouble() * player.height - 0.25D,
|
||||
player.posZ + (rand.nextDouble() - 0.5D), (this.rand.nextDouble() - 0.5D) * 2.0D, -rand.nextDouble(),
|
||||
(rand.nextDouble() - 0.5D) * 2.0D);
|
||||
}
|
||||
@@ -379,14 +384,14 @@ public class TravelController {
|
||||
}
|
||||
|
||||
public double getScaleForCandidate(Vector3d loc) {
|
||||
// try{
|
||||
// currentView.getEyePoint();
|
||||
// }catch(Exception e) {
|
||||
// //e.printStackTrace();
|
||||
// //System.out.println("crazypants.enderio.teleport.TravelController.getScaleForCandidate: " + currentView.getProjectionMatrix());
|
||||
// //System.out.println("crazypants.enderio.teleport.TravelController.getScaleForCandidate: " + currentView.getViewMatrix());
|
||||
// return 1;
|
||||
// }
|
||||
// try{
|
||||
// currentView.getEyePoint();
|
||||
// }catch(Exception e) {
|
||||
// //e.printStackTrace();
|
||||
// //System.out.println("crazypants.enderio.teleport.TravelController.getScaleForCandidate: " + currentView.getProjectionMatrix());
|
||||
// //System.out.println("crazypants.enderio.teleport.TravelController.getScaleForCandidate: " + currentView.getViewMatrix());
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
BlockCoord bc = new BlockCoord((int) loc.x, (int) loc.y, (int) loc.z);
|
||||
float ratio = -1;
|
||||
@@ -432,10 +437,13 @@ public class TravelController {
|
||||
return TravelSource.BLOCK.maxDistanceTravelledSq;
|
||||
}
|
||||
|
||||
private void sendTravelEvent(BlockCoord coord, TravelSource source, int powerUse) {
|
||||
private void sendTravelEvent(BlockCoord bc, TravelSource source, int powerUse) {
|
||||
PacketTravelEvent p = new PacketTravelEvent(bc.x, bc.y, bc.z, powerUse, source.getConserveMomentum());
|
||||
EnderIO.packetPipeline.sendToServer(p);
|
||||
|
||||
//TODO:1.7
|
||||
// Packet p = TravelPacketHandler.createMovePacket(coord.x, coord.y, coord.z, powerUse, source.getConserveMomentum());
|
||||
// PacketDispatcher.sendPacketToServer(p);
|
||||
// Packet p = TravelPacketHandler.createMovePacket(coord.x, coord.y, coord.z, powerUse, source.getConserveMomentum());
|
||||
// PacketDispatcher.sendPacketToServer(p);
|
||||
}
|
||||
|
||||
private BlockCoord getActiveTravelBlock(EntityClientPlayerMP player) {
|
||||
|
||||
Reference in new issue
Block a user