Search in sources :

Example 46 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class MinecartHooks method onMinecartEntityCollision.

@SuppressWarnings("unused")
@SubscribeEvent
public void onMinecartEntityCollision(MinecartCollisionEvent event) {
    EntityMinecart cart = event.getMinecart();
    Entity other = event.getCollider();
    if (cart.isPassenger(other))
        return;
    if (other instanceof EntityMinecart)
        LinkageManager.instance().tryAutoLink(cart, (EntityMinecart) other);
    testHighSpeedCollision(cart, other);
    if (EntityMinecart.getCollisionHandler() != this)
        if (other instanceof EntityLivingBase && WorldPlugin.isBlockAt(cart.worldObj, cart.getPosition(), RailcraftBlocks.TRACK_ELEVATOR.block()))
            if (other.getEntityBoundingBox().minY < cart.getEntityBoundingBox().maxY) {
                other.moveEntity(0, cart.getEntityBoundingBox().maxY - other.getEntityBoundingBox().minY, 0);
                other.onGround = true;
            }
    if (MiscTools.RANDOM.nextFloat() < 0.001f) {
        List<EntityMinecart> carts = EntitySearcher.findMinecarts().collidingWith(cart).with(Predicates.notInstanceOf(EntityMinecartCommandBlock.class)).at(cart.worldObj);
        if (carts.size() >= 12)
            primeToExplode(cart);
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 47 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class MinecartHooks method onItemUse.

@SuppressWarnings("unused")
@SubscribeEvent
public void onItemUse(PlayerInteractEvent.RightClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    World world = player.worldObj;
    if (Game.isClient(world))
        return;
    ItemStack itemStack = event.getItemStack();
    if (itemStack != null) {
        Item item = itemStack.getItem();
        if (item != null && CartTools.vanillaCartItemMap.containsKey(item)) {
            event.setUseItem(Event.Result.DENY);
            EntityMinecart placedCart = CartTools.placeCart(CartTools.vanillaCartItemMap.get(item), player.getGameProfile(), itemStack, world, event.getPos());
            if (placedCart != null && !player.capabilities.isCreativeMode)
                itemStack.stackSize--;
        }
    }
}
Also used : Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 48 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class MinecartHooks method onMinecartUpdate.

@SuppressWarnings("unused")
@SubscribeEvent
public void onMinecartUpdate(MinecartUpdateEvent event) {
    EntityMinecart cart = event.getMinecart();
    NBTTagCompound data = cart.getEntityData();
    // Fix flip
    float distance = MathTools.getDistanceBetweenAngles(cart.rotationYaw, cart.prevRotationYaw);
    float cutoff = 120F;
    if (distance < -cutoff || distance >= cutoff) {
        cart.rotationYaw += 180.0F;
        boolean reverse = ObfuscationReflectionHelper.getPrivateValue(EntityMinecart.class, cart, IS_REVERSED_VARIABLE_INDEX);
        ObfuscationReflectionHelper.setPrivateValue(EntityMinecart.class, cart, !reverse, IS_REVERSED_VARIABLE_INDEX);
        cart.rotationYaw = cart.rotationYaw % 360.0F;
    }
    //        } else
    if (data.getBoolean("ghost")) {
        cart.setGlowing(false);
        data.setBoolean("ghost", false);
    }
    // Code Added by Yopu to replace vanilla carts, deemed incomplete and unnecessary, pursuing other solutions
    //        if (classReplacements.containsKey(cart.getClass())) {
    //            cart.setDead();
    //            if (Game.isHost(cart.worldObj)) {
    //                EnumCart enumCart = classReplacements.get(cart.getClass());
    //                GameProfile cartOwner = CartTools.getCartOwner(cart);
    //                int x = MathHelper.floor_double(cart.posX);
    //                int y = MathHelper.floor_double(cart.posY);
    //                int z = MathHelper.floor_double(cart.posZ);
    //                CartUtils.placeCart(enumCart, cartOwner, enumCart.getCartItem(), cart.worldObj, x, y, z);
    //            }
    //            return;
    //        }
    Block block = WorldPlugin.getBlock(cart.worldObj, event.getPos());
    int launched = data.getInteger("Launched");
    if (TrackTools.isRailBlock(block)) {
        cart.fallDistance = 0;
        if (cart.isBeingRidden())
            cart.getPassengers().forEach(p -> p.fallDistance = 0);
        if (launched > 1)
            land(cart);
    } else if (launched == 1) {
        data.setInteger("Launched", 2);
        cart.setCanUseRail(true);
    } else if (launched > 1 && (cart.onGround || cart.isInsideOfMaterial(Material.CIRCUITS)))
        land(cart);
    int mountPrevention = data.getInteger("MountPrevention");
    if (mountPrevention > 0) {
        mountPrevention--;
        data.setInteger("MountPrevention", mountPrevention);
    }
    byte elevator = data.getByte("elevator");
    if (elevator < BlockTrackElevator.ELEVATOR_TIMER) {
        cart.setNoGravity(false);
    }
    if (elevator > 0) {
        elevator--;
        data.setByte("elevator", elevator);
    }
    byte derail = data.getByte("derail");
    if (derail > 0) {
        derail--;
        data.setByte("derail", derail);
    }
    if (data.getBoolean("explode")) {
        cart.getEntityData().setBoolean("explode", false);
        CartTools.explodeCart(cart);
    }
    if (data.getBoolean(CartTools.HIGH_SPEED_TAG))
        if (CartTools.cartVelocityIsLessThan(cart, HighSpeedTools.SPEED_CUTOFF))
            data.setBoolean(CartTools.HIGH_SPEED_TAG, false);
        else if (data.getInteger("Launched") == 0)
            HighSpeedTools.checkSafetyAndExplode(cart.worldObj, event.getPos(), cart);
    cart.motionX = Math.copySign(Math.min(Math.abs(cart.motionX), 9.5), cart.motionX);
    cart.motionY = Math.copySign(Math.min(Math.abs(cart.motionY), 9.5), cart.motionY);
    cart.motionZ = Math.copySign(Math.min(Math.abs(cart.motionZ), 9.5), cart.motionZ);
//        List entities = cart.worldObj.getEntitiesWithinAABB(EntityLiving.class, getMinecartCollisionBox(cart, COLLISION_EXPANSION));
//
//        if (entities != null) {
//            for (Entity entity : (List<Entity>) entities) {
//                if (entity != cart.riddenByEntity && entity.canBePushed()) {
//                    cart.applyEntityCollision(entity);
//                }
//            }
//        }
}
Also used : Item(net.minecraft.item.Item) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TrackToolsAPI(mods.railcraft.api.tracks.TrackToolsAPI) HighSpeedTools(mods.railcraft.common.blocks.tracks.behaivor.HighSpeedTools) IS_REVERSED_VARIABLE_INDEX(mods.railcraft.common.core.RailcraftConstants.IS_REVERSED_VARIABLE_INDEX) TrackTools(mods.railcraft.common.blocks.tracks.TrackTools) ItemStack(net.minecraft.item.ItemStack) MinecartInteractEvent(net.minecraftforge.event.entity.minecart.MinecartInteractEvent) Block(net.minecraft.block.Block) ObfuscationReflectionHelper(net.minecraftforge.fml.common.ObfuscationReflectionHelper) CartToolsAPI(mods.railcraft.api.carts.CartToolsAPI) EntityIronGolem(net.minecraft.entity.monster.EntityIronGolem) RailcraftConfig(mods.railcraft.common.core.RailcraftConfig) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) Nullable(javax.annotation.Nullable) EntitySearcher(mods.railcraft.common.plugins.forge.EntitySearcher) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) Event(net.minecraftforge.fml.common.eventhandler.Event) World(net.minecraft.world.World) IMinecartCollisionHandler(net.minecraftforge.common.IMinecartCollisionHandler) EntityMinecart(net.minecraft.entity.item.EntityMinecart) RailcraftBlocks(mods.railcraft.common.blocks.RailcraftBlocks) WorldPlugin(mods.railcraft.common.plugins.forge.WorldPlugin) MinecartCollisionEvent(net.minecraftforge.event.entity.minecart.MinecartCollisionEvent) mods.railcraft.common.util.misc(mods.railcraft.common.util.misc) EntityMinecartCommandBlock(net.minecraft.entity.item.EntityMinecartCommandBlock) List(java.util.List) ILinkageManager(mods.railcraft.api.carts.ILinkageManager) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) MinecartUpdateEvent(net.minecraftforge.event.entity.minecart.MinecartUpdateEvent) BlockTrackElevator(mods.railcraft.common.blocks.tracks.elevator.BlockTrackElevator) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) EntityMinecartCommandBlock(net.minecraft.entity.item.EntityMinecartCommandBlock) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 49 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class TrainTransferHelper method pullStack.

@Override
public ItemStack pullStack(EntityMinecart requester, Predicate<ItemStack> filter) {
    Iterable<EntityMinecart> carts = LinkageManager.instance().linkIterator(requester, LinkageManager.LinkType.LINK_A);
    ItemStack stack = _pullStack(requester, carts, filter);
    if (!InvTools.isEmpty(stack))
        return stack;
    carts = LinkageManager.instance().linkIterator(requester, LinkageManager.LinkType.LINK_B);
    return _pullStack(requester, carts, filter);
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 50 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project Railcraft by Railcraft.

the class TrainTransferHelper method pullFluid.

@Override
public FluidStack pullFluid(EntityMinecart requester, FluidStack fluidStack) {
    Iterable<EntityMinecart> carts = LinkageManager.instance().linkIterator(requester, LinkageManager.LinkType.LINK_A);
    FluidStack pulled = _pullFluid(requester, carts, fluidStack);
    if (pulled != null)
        return pulled;
    carts = LinkageManager.instance().linkIterator(requester, LinkageManager.LinkType.LINK_B);
    return _pullFluid(requester, carts, fluidStack);
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Aggregations

EntityMinecart (net.minecraft.entity.item.EntityMinecart)75 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 ItemStack (net.minecraft.item.ItemStack)17 List (java.util.List)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)11 Entity (net.minecraft.entity.Entity)9 DamageSource (net.minecraft.util.DamageSource)8 World (net.minecraft.world.World)8 ItemNTP32Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit)6 ItemNTP8Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit)6 ILinkageManager (mods.railcraft.api.carts.ILinkageManager)6 LocoBase (club.nsdn.nyasamarailway.entity.LocoBase)5 Nullable (javax.annotation.Nullable)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 MinecartUpdateEvent (net.minecraftforge.event.entity.minecart.MinecartUpdateEvent)4 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 ArrayList (java.util.ArrayList)3