Search in sources :

Example 21 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project ICBM-Classic by BuiltBrokenModding.

the class ThreadSky method run.

@Override
public void run() {
    int steps = (int) Math.ceil(Math.PI / Math.atan(1.0D / this.radius));
    for (int phi_n = 0; phi_n < 2 * steps; phi_n++) {
        for (int theta_n = 0; theta_n < steps; theta_n++) {
            double phi = Math.PI * 2 / steps * phi_n;
            double theta = Math.PI / steps * theta_n;
            Pos delta = new Pos(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi));
            float power = this.energy - (this.energy * this.position.world().rand.nextFloat() / 2);
            Location targetPosition = this.position;
            for (float var21 = 0.3F; power > 0f; power -= var21 * 0.75F * 10) {
                if (targetPosition.distance(position) > this.radius) {
                    break;
                }
                Block blockID = this.position.world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                if (blockID != Blocks.air) {
                    if (blockID == Blocks.bedrock) {
                        break;
                    }
                    float resistance = this.callBack.getResistance(this.position.world(), position.toPos(), targetPosition.toPos(), source, blockID);
                    power -= resistance;
                    if (power > 0f) {
                        this.results.add(targetPosition.add(new Pos(0, 1, 0)).toPos());
                    }
                }
                targetPosition = targetPosition.add(delta);
            }
        }
    }
    super.run();
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 22 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project Engine by VoltzEngine-Project.

the class PacketTile method handle.

/**
     * Called to handler a packet when it is received
     *
     * @param player - player who received the packet
     * @param tile   - tile who is receiving the packet
     */
public void handle(EntityPlayer player, TileEntity tile) {
    final Location location = new Location(player.worldObj, x, y, z);
    sender_$eq(player);
    if (tile == null) {
        Engine.instance.logger().error(new PacketTileReadException(location, "Null tile"));
    } else if (tile.isInvalid()) {
        Engine.instance.logger().error(new PacketTileReadException(location, "Invalidated tile"));
    } else if (tile instanceof IPacketIDReceiver) {
        if (((IPacketIDReceiver) tile).shouldReadPacket(player, location, this)) {
            try {
                IPacketIDReceiver receiver = (IPacketIDReceiver) tile;
                ByteBuf buf = data().slice();
                int id;
                try {
                    id = buf.readInt();
                } catch (IndexOutOfBoundsException ex) {
                    Engine.instance.logger().error(new PacketIDException(location));
                    return;
                }
                receiver.read(buf, id, player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
                Engine.instance.logger().error("Error: ", e);
            } catch (NullPointerException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
                Engine.instance.logger().error("Error: ", e);
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                Engine.instance.logger().error("Error: ", e);
            }
        } else {
            Engine.instance.logger().error("Error: " + tile + " rejected packet " + this + " due to invalid conditions.");
        }
    } else if (tile instanceof IPacketReceiver) {
        if (((IPacketReceiver) tile).shouldReadPacket(player, location, this)) {
            try {
                IPacketReceiver receiver = (IPacketReceiver) tile;
                receiver.read(data().slice(), player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                e.printStackTrace();
            }
        } else {
            Engine.instance.logger().error("Error: " + tile + " rejected packet " + this + " due to invalid conditions.");
        }
    } else {
        Engine.instance.logger().error(new PacketTileReadException(location, "Unsupported action for " + tile));
    }
}
Also used : IPacketReceiver(com.builtbroken.mc.core.network.IPacketReceiver) IPacketIDReceiver(com.builtbroken.mc.core.network.IPacketIDReceiver) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) ByteBuf(io.netty.buffer.ByteBuf) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException) Location(com.builtbroken.mc.imp.transform.vector.Location) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException)

Example 23 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project Engine by VoltzEngine-Project.

the class InteractionHandler method onPlayerInteract.

@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
    if (!event.entityPlayer.worldObj.isRemote && event.entityPlayer != null) {
        Location vec = new Location(event.entityPlayer.worldObj, event.x, event.y, event.z);
        TileEntity tile = vec.getTileEntity();
        if (event.action == Action.RIGHT_CLICK_BLOCK) {
            //Handle IRemovable allow more uniform removal of blocks
            if (tile instanceof IRemovable) {
                boolean do_drop = false;
                List<ItemStack> drops;
                if (tile instanceof ICustomRemoval) {
                    do_drop = ((ICustomRemoval) tile).canBeRemoved(event.entityPlayer);
                } else if (tile instanceof ISneakWrenchable) {
                    do_drop = event.entityPlayer.isSneaking() && WrenchUtility.isHoldingWrench(event.entityPlayer);
                } else if (tile instanceof IWrenchable) {
                    do_drop = WrenchUtility.isHoldingWrench(event.entityPlayer);
                } else if (tile instanceof ISneakPickup) {
                    do_drop = event.entityPlayer.isSneaking() && event.entityPlayer.getHeldItem() == null;
                } else {
                    do_drop = tile instanceof IPickup && event.entityPlayer.getHeldItem() == null;
                }
                if (do_drop) {
                    drops = ((IRemovable) tile).getRemovedItems(event.entityPlayer);
                    //Not sure if we need to cancel but there is nothing to right click after this
                    if (event.isCancelable()) {
                        event.setCanceled(true);
                    }
                    //Drop all items
                    try {
                        vec.world().removeTileEntity(vec.xi(), vec.yi(), vec.zi());
                        vec.setBlock(Blocks.air);
                        if (drops != null && !drops.isEmpty()) {
                            for (ItemStack item : drops) {
                                if (!event.entityPlayer.inventory.addItemStackToInventory(item)) {
                                    InventoryUtility.dropItemStack(vec, item);
                                } else {
                                    event.entityPlayer.inventory.markDirty();
                                }
                            }
                            event.entityPlayer.inventoryContainer.detectAndSendChanges();
                        }
                    } catch (Exception e) {
                        Engine.instance.logger().error("Failed to pick up block using event system");
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IRemovable(com.builtbroken.mc.api.tile.IRemovable) ItemStack(net.minecraft.item.ItemStack) Location(com.builtbroken.mc.imp.transform.vector.Location) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 24 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project Engine by VoltzEngine-Project.

the class PacketGui method handleClientSide.

@Override
public void handleClientSide(EntityPlayer player) {
    GuiScreen screen = Minecraft.getMinecraft().currentScreen;
    Location location = new Location(player);
    if (screen instanceof IPacketIDReceiver) {
        if (((IPacketIDReceiver) screen).shouldReadPacket(player, location, this)) {
            try {
                IPacketIDReceiver receiver = (IPacketIDReceiver) screen;
                ByteBuf buf = data().slice();
                int id;
                try {
                    id = buf.readInt();
                } catch (IndexOutOfBoundsException ex) {
                    Engine.instance.logger().error(new PacketIDException(location));
                    return;
                }
                receiver.read(buf, id, player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
                Engine.instance.logger().error("Error: ", e);
            } catch (NullPointerException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
                Engine.instance.logger().error("Error: ", e);
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                Engine.instance.logger().error("Error: ", e);
            }
        } else {
            Engine.instance.logger().error("Error: " + screen + " rejected packet " + this + " due to invalid conditions.");
        }
    } else if (screen instanceof IPacketReceiver) {
        if (((IPacketReceiver) screen).shouldReadPacket(player, location, this)) {
            try {
                IPacketReceiver receiver = (IPacketReceiver) screen;
                receiver.read(data().slice(), player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                e.printStackTrace();
            }
        } else {
            Engine.instance.logger().error("Error: " + screen + " rejected packet " + this + " due to invalid conditions.");
        }
    } else {
        Engine.instance.logger().error(new PacketTileReadException(location, "Unsupported action for " + screen));
    }
}
Also used : IPacketReceiver(com.builtbroken.mc.core.network.IPacketReceiver) IPacketIDReceiver(com.builtbroken.mc.core.network.IPacketIDReceiver) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) GuiScreen(net.minecraft.client.gui.GuiScreen) ByteBuf(io.netty.buffer.ByteBuf) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException) Location(com.builtbroken.mc.imp.transform.vector.Location) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException)

Example 25 with Location

use of com.builtbroken.mc.imp.transform.vector.Location in project Engine by VoltzEngine-Project.

the class PacketGui method handleServerSide.

@Override
public void handleServerSide(EntityPlayer player) {
    Container container = player.openContainer;
    Location location = new Location(player);
    if (container instanceof IPacketIDReceiver) {
        if (((IPacketIDReceiver) container).shouldReadPacket(player, location, this)) {
            try {
                IPacketIDReceiver receiver = (IPacketIDReceiver) container;
                ByteBuf buf = data().slice();
                int id;
                try {
                    id = buf.readInt();
                } catch (IndexOutOfBoundsException ex) {
                    Engine.instance.logger().error(new PacketIDException(location));
                    return;
                }
                receiver.read(buf, id, player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
                Engine.instance.logger().error("Error: ", e);
            } catch (NullPointerException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Null pointer while reading data", e));
                Engine.instance.logger().error("Error: ", e);
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                Engine.instance.logger().error("Error: ", e);
            }
        } else {
            Engine.instance.logger().error("Error: " + container + " rejected packet " + this + " due to invalid conditions.");
        }
    } else if (container instanceof IPacketReceiver) {
        if (((IPacketReceiver) container).shouldReadPacket(player, location, this)) {
            try {
                IPacketReceiver receiver = (IPacketReceiver) container;
                receiver.read(data().slice(), player, this);
            } catch (IndexOutOfBoundsException e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Packet was read past it's size."));
            } catch (Exception e) {
                Engine.instance.logger().error(new PacketTileReadException(location, "Failed to read packet", e));
                e.printStackTrace();
            }
        } else {
            Engine.instance.logger().error("Error: " + container + " rejected packet " + this + " due to invalid conditions.");
        }
    } else {
        Engine.instance.logger().error(new PacketTileReadException(location, "Unsupported action for " + container));
    }
}
Also used : IPacketReceiver(com.builtbroken.mc.core.network.IPacketReceiver) Container(net.minecraft.inventory.Container) IPacketIDReceiver(com.builtbroken.mc.core.network.IPacketIDReceiver) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) ByteBuf(io.netty.buffer.ByteBuf) PacketTileReadException(com.builtbroken.mc.core.network.ex.PacketTileReadException) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException) Location(com.builtbroken.mc.imp.transform.vector.Location) PacketIDException(com.builtbroken.mc.core.network.ex.PacketIDException)

Aggregations

Location (com.builtbroken.mc.imp.transform.vector.Location)30 Pos (com.builtbroken.mc.imp.transform.vector.Pos)11 Block (net.minecraft.block.Block)7 TileEntity (net.minecraft.tileentity.TileEntity)6 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)5 HashMap (java.util.HashMap)5 IMultiTile (com.builtbroken.mc.api.tile.multiblock.IMultiTile)4 FakeWorld (com.builtbroken.mc.testing.junit.world.FakeWorld)4 ByteBuf (io.netty.buffer.ByteBuf)4 Map (java.util.Map)4 World (net.minecraft.world.World)4 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)4 IPacketIDReceiver (com.builtbroken.mc.core.network.IPacketIDReceiver)3 IPacketReceiver (com.builtbroken.mc.core.network.IPacketReceiver)3 PacketIDException (com.builtbroken.mc.core.network.ex.PacketIDException)3 PacketTileReadException (com.builtbroken.mc.core.network.ex.PacketTileReadException)3 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 Entity (net.minecraft.entity.Entity)3 Test (org.junit.Test)3 AbstractTest (com.builtbroken.mc.testing.junit.AbstractTest)2