Search in sources :

Example 31 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project NyaSamaRailway by NSDN.

the class TileEntityRailReception method cart.

public static void cart(boolean isAnti, EntityMinecart cart, TileEntityRailReception rail, EntityPlayer player, boolean playerDetectable) {
    if (rail == null)
        return;
    if (cart == null)
        return;
    World world = rail.worldObj;
    int x = rail.xCoord, y = rail.yCoord, z = rail.zCoord;
    double maxV;
    if (!playerDetectable) {
        maxV = 0.1;
        if (isRailPowered(world, x, y, z)) {
            if (isAnti) {
                if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                    if (cart.motionZ < -maxV) {
                        // cart.motionZ < -maxV
                        if (cart.motionZ > -maxV * 1.5)
                            cart.motionZ = -maxV * 1.5;
                    } else {
                        if (cart.motionZ <= 0)
                            cart.motionZ = 0.005;
                        if (cart.motionZ < maxV)
                            cart.motionZ = Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionZ), 0.1, 1.0, 0.1, 0.02);
                    }
                } else {
                    if (cart.motionX > maxV) {
                        // cart.motionX > maxV
                        if (cart.motionX < maxV * 1.5)
                            cart.motionX = maxV * 1.5;
                    } else {
                        if (cart.motionX >= 0)
                            cart.motionX = -0.005;
                        if (cart.motionX > -maxV)
                            cart.motionX = -Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionX), 0.1, 1.0, 0.1, 0.02);
                    }
                }
            } else {
                if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                    if (cart.motionZ > maxV) {
                        // cart.motionZ > maxV
                        if (cart.motionZ < maxV * 1.5)
                            cart.motionZ = maxV * 1.5;
                    } else {
                        if (cart.motionZ >= 0)
                            cart.motionZ = -0.005;
                        if (cart.motionZ > -maxV)
                            cart.motionZ = -Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionZ), 0.1, 1.0, 0.1, 0.02);
                    }
                } else {
                    if (cart.motionX < -maxV) {
                        // cart.motionX < -maxV
                        if (cart.motionX > -maxV * 1.5)
                            cart.motionX = -maxV * 1.5;
                    } else {
                        if (cart.motionX <= 0)
                            cart.motionX = 0.005;
                        if (cart.motionX < maxV)
                            cart.motionX = Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionX), 0.1, 1.0, 0.1, 0.02);
                    }
                }
            }
        } else {
            if (Math.abs(cart.motionX) > maxV || Math.abs(cart.motionZ) > maxV) {
                cart.motionX = Math.signum(cart.motionX) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionX), 0.1, 1.0, 1.0, 1.0, 0.05, 0.02);
                cart.motionZ = Math.signum(cart.motionZ) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionZ), 0.1, 1.0, 1.0, 1.0, 0.05, 0.02);
            } else {
                if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                    cart.motionZ = 0.0D;
                } else {
                    cart.motionX = 0.0D;
                }
            }
        }
    } else {
        maxV = 0.2;
        if (rail.cartType.equals("loco")) {
            return;
        }
        if (rail.cartType.isEmpty() && (cart.motionX * cart.motionX + cart.motionZ * cart.motionZ == 0))
            registerCart(rail, cart);
        if (!world.isBlockIndirectlyGettingPowered(x, y, z)) {
            if (player != null) {
                if ((cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0) && !rail.enable) {
                    if ((Math.abs(cart.motionX) > maxV / 2) || (Math.abs(cart.motionZ) > maxV / 2)) {
                        cart.motionX = (Math.signum(cart.motionX) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionX), 0.1D, 1.0D, 1.0D, 1.0D, 0.05D, 0.02D));
                        cart.motionZ = (Math.signum(cart.motionZ) * Dynamics.LocoMotions.calcVelocityDown(Math.abs(cart.motionZ), 0.1D, 1.0D, 1.0D, 1.0D, 0.05D, 0.02D));
                    } else {
                        rail.enable = true;
                        rail.doorCtrl = true;
                        if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                            cart.motionZ = 0.0D;
                        } else {
                            cart.motionX = 0.0D;
                        }
                        cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
                        if (player instanceof EntityPlayerMP && rail.setDelay == 10) {
                            player.addChatComponentMessage(new ChatComponentTranslation("info.reception.pause", rail.setDelay));
                            world.playSoundAtEntity(cart, "nyasamarailway:info.reception.pause", 0.5F, 1.0F);
                        }
                    }
                } else {
                    if (rail.delay < rail.setDelay * 20 && rail.enable) {
                        boolean isEnabled = false;
                        if (rail.getSender() != null)
                            isEnabled = rail.senderIsPowered();
                        if (!isEnabled)
                            rail.delay += 1;
                        else {
                            rail.count += 1;
                            if (rail.delay + rail.count == rail.setDelay * 15) {
                                rail.delay = rail.setDelay * 15 - 1;
                                rail.count += 1;
                                if (player instanceof EntityPlayerMP) {
                                    player.addChatComponentMessage(new ChatComponentTranslation("info.reception.delay"));
                                    world.playSoundAtEntity(cart, "nyasamarailway:info.reception.delay", 0.5F, 1.0F);
                                }
                            }
                        }
                        if (rail.delay == rail.setDelay * 15) {
                            rail.count = 0;
                            rail.doorCtrl = false;
                            if (player instanceof EntityPlayerMP) {
                                player.addChatComponentMessage(new ChatComponentTranslation("info.reception.ready"));
                                world.playSoundAtEntity(cart, "nyasamarailway:info.reception.ready", 0.5F, 1.0F);
                            }
                        }
                        cart.motionX = 0.0D;
                        cart.motionZ = 0.0D;
                        cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
                    } else {
                        if (isAnti) {
                            if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                                if (cart.motionZ < -maxV) {
                                    if (cart.motionZ > -maxV * 1.5D)
                                        cart.motionZ = (-maxV * 1.5D);
                                } else {
                                    if (cart.motionZ <= 0.0D)
                                        cart.motionZ = 0.005D;
                                    if (cart.motionZ < maxV) {
                                        cart.motionZ = Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionZ), 0.1D, 1.0D, 0.1D, 0.02D);
                                    }
                                }
                            } else {
                                if (cart.motionX > maxV) {
                                    if (cart.motionX < maxV * 1.5D)
                                        cart.motionX = (maxV * 1.5D);
                                } else {
                                    if (cart.motionX >= 0.0D)
                                        cart.motionX = -0.005D;
                                    if (cart.motionX > -maxV) {
                                        cart.motionX = -Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionX), 0.1D, 1.0D, 0.1D, 0.02D);
                                    }
                                }
                            }
                        } else {
                            if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                                if (cart.motionZ > maxV) {
                                    if (cart.motionZ < maxV * 1.5D)
                                        cart.motionZ = (maxV * 1.5D);
                                } else {
                                    if (cart.motionZ >= 0.0D)
                                        cart.motionZ = -0.005D;
                                    if (cart.motionZ > -maxV) {
                                        cart.motionZ = -Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionZ), 0.1D, 1.0D, 0.1D, 0.02D);
                                    }
                                }
                            } else {
                                if (cart.motionX < -maxV) {
                                    if (cart.motionX > -maxV * 1.5D)
                                        cart.motionX = (-maxV * 1.5D);
                                } else {
                                    if (cart.motionX <= 0.0D)
                                        cart.motionX = 0.005D;
                                    if (cart.motionX < maxV) {
                                        cart.motionX = Dynamics.LocoMotions.calcVelocityUp(Math.abs(cart.motionX), 0.1D, 1.0D, 0.1D, 0.02D);
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                cart.motionX = 0.0D;
                cart.motionZ = 0.0D;
                cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
                rail.reset();
            }
        } else {
            if (isAnti) {
                if (cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0) {
                    if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                        if (cart.posZ - 0.5 < z) {
                            cart.killMinecart(new DamageSource("nsr"));
                        }
                    } else {
                        if (cart.posX - 0.5 > x) {
                            cart.killMinecart(new DamageSource("nsr"));
                        }
                    }
                }
            } else {
                if (cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0) {
                    if (getRailDirection(world, x, y, z) == RailDirection.NS) {
                        if (cart.posZ - 0.5 > z) {
                            cart.killMinecart(new DamageSource("nsr"));
                        }
                    } else {
                        if (cart.posX - 0.5 < x) {
                            cart.killMinecart(new DamageSource("nsr"));
                        }
                    }
                }
            }
        }
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) World(net.minecraft.world.World)

Example 32 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project NyaSamaRailway by NSDN.

the class BlockRailSniffer method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (world.getTileEntity(x, y, z) == null)
        return false;
    if (world.getTileEntity(x, y, z) instanceof RailSniffer) {
        RailSniffer sniffer = (RailSniffer) world.getTileEntity(x, y, z);
        ItemStack stack = player.getCurrentEquippedItem();
        if (stack != null) {
            NBTTagList list = Util.getTagListFromNGT(stack);
            if (list == null)
                return false;
            if (!world.isRemote) {
                String code = NSASM.getCodeString(list);
                sniffer.nsasmState = RailSniffer.NSASM_IDLE;
                sniffer.nsasmCode = code;
                player.addChatComponentMessage(new ChatComponentTranslation("info.sniffer.set"));
            }
            return true;
        }
    }
    return false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) ItemStack(net.minecraft.item.ItemStack) TileEntityRailSniffer(club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer)

Example 33 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project NyaSamaRailway by NSDN.

the class Item74HC04 method onConnectorUseLast.

@Override
public boolean onConnectorUseLast(EntityPlayer player, UUID uuid, TileEntity tileEntity) {
    if (Railcraft.getInstance() != null) {
        if (Railcraft.getInstance().verifySwitch(tileEntity)) {
            if (receiverRails.containsKey(uuid)) {
                if (receiverRails.get(uuid) instanceof TileEntityActuator) {
                    TileEntityActuator actuator = (TileEntityActuator) receiverRails.get(uuid);
                    if (actuator.getTarget() != tileEntity) {
                        actuator.setTarget(tileEntity);
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.connected"));
                        updateTileEntity(actuator);
                        updateTileEntity(tileEntity);
                    } else {
                        actuator.setTarget(null);
                        if (player instanceof EntityPlayerMP)
                            player.addChatComponentMessage(new ChatComponentTranslation("info.signal.disconnected"));
                        updateTileEntity(actuator);
                        updateTileEntity(tileEntity);
                    }
                }
                receiverRails.remove(uuid);
            } else {
                if (player instanceof EntityPlayerMP)
                    player.addChatComponentMessage(new ChatComponentTranslation("info.signal.error"));
            }
            return true;
        }
    }
    return false;
}
Also used : TileEntityActuator(club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 34 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project NyaSamaRailway by NSDN.

the class ItemNTP32Bit method clearCart.

public void clearCart(ItemStack itemStack, EntityPlayer player) {
    int[] array = new int[] { -1 };
    power.set(itemStack, 0);
    brake.set(itemStack, 5);
    dir.set(itemStack, 0);
    carts.set(itemStack, array);
    if (player instanceof EntityPlayerMP) {
        TrainPacket packet = new TrainPacket();
        packet.fromStack(itemStack);
        NetworkWrapper.instance.sendTo(packet, (EntityPlayerMP) player);
    }
    player.addChatComponentMessage(new ChatComponentTranslation("info.ntp.cleared"));
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TrainPacket(club.nsdn.nyasamarailway.network.TrainPacket)

Example 35 with ChatComponentTranslation

use of net.minecraft.util.ChatComponentTranslation in project NyaSamaRailway by NSDN.

the class ItemPierBuilder method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    if (block == null)
        return false;
    if (player.isSneaking()) {
        endBlock = block;
        if (player instanceof EntityPlayerMP)
            player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.endBlock", endBlock.getLocalizedName()));
    } else {
        if (block instanceof BlockPierTag) {
            if (endBlock == null)
                return false;
            world.setBlock(x, y, z, Blocks.air);
            block = world.getBlock(x, y + 1, z);
            if (player instanceof EntityPlayerMP)
                player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.begin"));
            // dy = -1 to use pier tag
            for (int dy = -1; !reachesEndBlock(world, x, y - dy - 1, z); dy++) {
                traversalCounter = 0;
                TraversalBlocks(world, block, x, y - dy, z);
                if (traversalCounter > TRAVERSAL_MAX) {
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.abort"));
                    break;
                }
            }
            if (player instanceof EntityPlayerMP)
                player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.finish"));
        } else {
            if (isFenceBuilding(world, x, y, z)) {
                Block fence = world.getBlock(x, y, z);
                int meta = world.getBlockMetadata(x, y, z);
                if (player instanceof EntityPlayerMP)
                    player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.fence"));
                traversalCounter = 0;
                TraversalFence(world, fence, meta, x, y, z);
                if (traversalCounter > TRAVERSAL_MAX) {
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.abort"));
                } else {
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.finish"));
                }
            } else if (isRailBuilding(world, x, y, z)) {
                Block rail = world.getBlock(x, y, z);
                Block base = world.getBlock(x, y - 1, z);
                if (getEdge(world, x, y, z) == null)
                    return false;
                Block edge = getEdge(world, x, y, z);
                int edgeMeta = getEdgeMeta(world, x, y, z);
                if (player instanceof EntityPlayerMP)
                    player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.rails"));
                traversalCounter = 0;
                TraversalRails(world, rail, base, edge, edgeMeta, x, y - 1, z);
                if (traversalCounter > TRAVERSAL_MAX) {
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.abort"));
                } else {
                    if (player instanceof EntityPlayerMP)
                        player.addChatComponentMessage(new ChatComponentTranslation("info.PierBuilder.finish"));
                }
            } else
                return false;
        }
    }
    return !world.isRemote;
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPierTag(club.nsdn.nyasamarailway.tileblock.functional.BlockPierTag)

Aggregations

ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)77 ItemStack (net.minecraft.item.ItemStack)19 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 TileEntity (net.minecraft.tileentity.TileEntity)13 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)11 ArrayList (java.util.ArrayList)5 Block (net.minecraft.block.Block)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 World (net.minecraft.world.World)4 Item1N4148 (club.nsdn.nyasamarailway.item.tool.Item1N4148)3 ItemNTP32Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit)3 ItemNTP8Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit)3 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)3 TileEntityActuator (club.nsdn.nyasamatelecom.api.tileentity.TileEntityActuator)3 EntityItem (net.minecraft.entity.item.EntityItem)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 TileEntityRailSniffer (club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer)2 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)2 Side (cpw.mods.fml.relauncher.Side)2